Skip to content

Commit

Permalink
Merge pull request #2485 from ousttrue/fix/collidergroup_separate
Browse files Browse the repository at this point in the history
VRM10SpringBoneColliderGroup 改善
  • Loading branch information
ousttrue authored Nov 7, 2024
2 parents 428986b + d652384 commit c81242b
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,12 @@ public class VRM10SpringBoneCollider : MonoBehaviour

public bool IsSelected => GetInstanceID() == SelectedGuid;

public void OnDrawGizmosSelected()
void OnDrawGizmosSelected()
{
DrawGizmos();
}

public void DrawGizmos()
{
Gizmos.matrix = transform.localToWorldMatrix;
switch (ColliderType)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;

namespace UniVRM10
Expand All @@ -14,5 +15,80 @@ public class VRM10SpringBoneColliderGroup : MonoBehaviour

[SerializeField]
public List<VRM10SpringBoneCollider> Colliders = new List<VRM10SpringBoneCollider>();

string GetName()
{
if (!string.IsNullOrEmpty(Name))
{
return Name;
}
return Colliders[0].name;
}

#if UNITY_EDITOR
[ContextMenu("Create child and move to that")]
public void Separate()
{
var vrm = GetComponentInParent<Vrm10Instance>();
if (vrm == null)
{
return;
}
if (Colliders == null || Colliders.Count == 0)
{
return;
}

UnityEditor.Undo.IncrementCurrentGroup();
UnityEditor.Undo.SetCurrentGroupName("VRM10SpringBoneColliderGroup.Separate");
var undo = UnityEditor.Undo.GetCurrentGroup();

var child = new GameObject($"group: {GetName()}");
UnityEditor.Undo.RegisterCreatedObjectUndo(child, "child");
UnityEditor.Undo.SetTransformParent(child.transform, transform, "setParent");

var group = UnityEditor.Undo.AddComponent<VRM10SpringBoneColliderGroup>(child);
group.Name = Name;
group.Colliders = Colliders.ToList();
for (int i = 0; i < vrm.SpringBone.ColliderGroups.Count; ++i)
{
if (vrm.SpringBone.ColliderGroups[i] == this)
{
vrm.SpringBone.ColliderGroups[i] = group;
}
}
foreach (var spring in vrm.SpringBone.Springs)
{
for (int i = 0; i < spring.ColliderGroups.Count; ++i)
{
if (spring.ColliderGroups[i] == this)
{
spring.ColliderGroups[i] = group;
}
}
}

if (Application.isPlaying)
{
Destroy(this);
}
else
{
UnityEditor.Undo.DestroyObjectImmediate(this);
}

UnityEditor.Undo.RegisterFullObjectHierarchyUndo(vrm.gameObject, "VRM10SpringBoneColliderGroup.Separate");

UnityEditor.Undo.CollapseUndoOperations(undo);
}
#endif

public void OnDrawGizmosSelected()
{
foreach (var collider in Colliders)
{
collider.DrawGizmos();
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class VRM10SpringBoneJoint : MonoBehaviour
[SerializeField, Range(0, 1)]
public float m_dragForce = 0.4f;

[SerializeField]
[SerializeField]
public float m_jointRadius = 0.02f;

[SerializeField]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public void DrawGizmos()
{
foreach (var collider in group.Colliders)
{
collider.OnDrawGizmosSelected();
collider.DrawGizmos();
}
}
m_drawCollider = 0;
Expand Down

0 comments on commit c81242b

Please sign in to comment.