Add reselect button for colliders

This commit is contained in:
LanternaBlender
2024-06-06 23:42:41 +09:00
parent 9e9a8b0229
commit 46d3de45ec

View File

@@ -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<VRM10SpringBoneCollider>();
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<VRM10SpringBoneColliderEditorWindow>();
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<VRM10SpringBoneCollider>();
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();
}
}
}