From 44a9bc5aeb4ef57a02a0ab22aa48af0c2a909269 Mon Sep 17 00:00:00 2001 From: ousttrue Date: Thu, 7 Nov 2024 23:42:12 +0900 Subject: [PATCH 1/2] impl OnDrawGizmosSelected and Separate for VRM10SpringBoneColliderGroup --- .../SpringBone/VRM10SpringBoneCollider.cs | 7 +- .../VRM10SpringBoneColliderGroup.cs | 74 +++++++++++++++++++ .../SpringBone/VRM10SpringBoneJoint.cs | 2 +- .../Vrm10Instance/Vrm10InstanceSpringBone.cs | 2 +- 4 files changed, 82 insertions(+), 3 deletions(-) diff --git a/Assets/VRM10/Runtime/Components/SpringBone/VRM10SpringBoneCollider.cs b/Assets/VRM10/Runtime/Components/SpringBone/VRM10SpringBoneCollider.cs index 9a0df19af4..482707acc6 100644 --- a/Assets/VRM10/Runtime/Components/SpringBone/VRM10SpringBoneCollider.cs +++ b/Assets/VRM10/Runtime/Components/SpringBone/VRM10SpringBoneCollider.cs @@ -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) diff --git a/Assets/VRM10/Runtime/Components/SpringBone/VRM10SpringBoneColliderGroup.cs b/Assets/VRM10/Runtime/Components/SpringBone/VRM10SpringBoneColliderGroup.cs index e1c782085e..5d0eeca49a 100644 --- a/Assets/VRM10/Runtime/Components/SpringBone/VRM10SpringBoneColliderGroup.cs +++ b/Assets/VRM10/Runtime/Components/SpringBone/VRM10SpringBoneColliderGroup.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Linq; using UnityEngine; namespace UniVRM10 @@ -14,5 +15,78 @@ public class VRM10SpringBoneColliderGroup : MonoBehaviour [SerializeField] public List Colliders = new List(); + + string GetName() + { + if (!string.IsNullOrEmpty(Name)) + { + return Name; + } + return Colliders[0].name; + } + + [ContextMenu("Create child and move to that")] + public void Separate() + { + var vrm = GetComponentInParent(); + 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(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); + } + + public void OnDrawGizmosSelected() + { + foreach (var collider in Colliders) + { + collider.DrawGizmos(); + } + } } } \ No newline at end of file diff --git a/Assets/VRM10/Runtime/Components/SpringBone/VRM10SpringBoneJoint.cs b/Assets/VRM10/Runtime/Components/SpringBone/VRM10SpringBoneJoint.cs index a0e751a846..6e8319f23a 100644 --- a/Assets/VRM10/Runtime/Components/SpringBone/VRM10SpringBoneJoint.cs +++ b/Assets/VRM10/Runtime/Components/SpringBone/VRM10SpringBoneJoint.cs @@ -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] diff --git a/Assets/VRM10/Runtime/Components/Vrm10Instance/Vrm10InstanceSpringBone.cs b/Assets/VRM10/Runtime/Components/Vrm10Instance/Vrm10InstanceSpringBone.cs index c6ce219903..91a4b3b672 100644 --- a/Assets/VRM10/Runtime/Components/Vrm10Instance/Vrm10InstanceSpringBone.cs +++ b/Assets/VRM10/Runtime/Components/Vrm10Instance/Vrm10InstanceSpringBone.cs @@ -101,7 +101,7 @@ public void DrawGizmos() { foreach (var collider in group.Colliders) { - collider.OnDrawGizmosSelected(); + collider.DrawGizmos(); } } m_drawCollider = 0; From 109feb75395561f053ef0872f43190cfab24eeb6 Mon Sep 17 00:00:00 2001 From: ousttrue Date: Fri, 8 Nov 2024 00:00:42 +0900 Subject: [PATCH 2/2] =?UTF-8?q?editor=20=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Components/SpringBone/VRM10SpringBoneColliderGroup.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Assets/VRM10/Runtime/Components/SpringBone/VRM10SpringBoneColliderGroup.cs b/Assets/VRM10/Runtime/Components/SpringBone/VRM10SpringBoneColliderGroup.cs index 5d0eeca49a..a899cc2083 100644 --- a/Assets/VRM10/Runtime/Components/SpringBone/VRM10SpringBoneColliderGroup.cs +++ b/Assets/VRM10/Runtime/Components/SpringBone/VRM10SpringBoneColliderGroup.cs @@ -25,6 +25,7 @@ string GetName() return Colliders[0].name; } +#if UNITY_EDITOR [ContextMenu("Create child and move to that")] public void Separate() { @@ -80,6 +81,7 @@ public void Separate() UnityEditor.Undo.CollapseUndoOperations(undo); } +#endif public void OnDrawGizmosSelected() {