diff --git a/Assets/VRM10/Editor/Components/SpringBone/VRM10SpringBoneColliderDrawer.cs b/Assets/VRM10/Editor/Components/SpringBone/VRM10SpringBoneColliderDrawer.cs index 72820c84e..1548a7e71 100644 --- a/Assets/VRM10/Editor/Components/SpringBone/VRM10SpringBoneColliderDrawer.cs +++ b/Assets/VRM10/Editor/Components/SpringBone/VRM10SpringBoneColliderDrawer.cs @@ -8,9 +8,21 @@ namespace UniVRM10 { public override void OnGUI(Rect rect, SerializedProperty property, GUIContent label) { + const string ButtonLabel = "Reselect"; + var ButtonSize = GUI.skin.button.CalcSize(new GUIContent(ButtonLabel)); try { - EditorGUI.ObjectField(rect, property, new GUIContent(((VRM10SpringBoneCollider)property.objectReferenceValue).GetIdentificationName())); + var collider = property.objectReferenceValue as VRM10SpringBoneCollider; + EditorGUI.ObjectField(rect, property, new GUIContent(collider.GetIdentificationName())); + + var colliders = collider.transform.GetComponents(); + if (colliders.Length > 1) + { + if (GUI.Button(new Rect(rect.x + EditorGUIUtility.labelWidth - ButtonSize.x, rect.y, ButtonSize.x, rect.height), ButtonLabel)) + { + VRM10SpringBoneColliderEditorWindow.Show(property); + } + } } catch { @@ -18,4 +30,47 @@ namespace UniVRM10 } } } + + public class VRM10SpringBoneColliderEditorWindow : EditorWindow + { + private static SerializedProperty targetProperty; + private Vector2 scrollPosition; + + public static void Show(SerializedProperty property) + { + targetProperty = property; + var window = CreateInstance(); + window.titleContent = new GUIContent("Reselect Collider from \"" + (property.objectReferenceValue as VRM10SpringBoneCollider).transform.name + "\""); + window.ShowAuxWindow(); + } + + private void OnGUI() + { + if (targetProperty is null) + { + Close(); + return; + } + + var transform = (targetProperty.objectReferenceValue as VRM10SpringBoneCollider).transform; + var colliders = transform.GetComponents(); + if (colliders.Length == 0) + { + Close(); + return; + } + + scrollPosition = GUILayout.BeginScrollView(scrollPosition); + foreach (var collider in colliders) + { + if (GUILayout.Button(collider.GetIdentificationName())) + { + targetProperty.objectReferenceValue = collider; + targetProperty.serializedObject.ApplyModifiedProperties(); + Close(); + } + } + GUILayout.EndScrollView(); + } + } } \ No newline at end of file