Merge pull request #2306 from LanternaBlender/ColliderIdentification

Improved display of VRM10SpringBoneCollider on inspector
This commit is contained in:
ousttrue 2024-06-04 16:12:11 +09:00 committed by GitHub
commit fa641548a9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 65 additions and 1 deletions

View File

@ -0,0 +1,21 @@
using UnityEditor;
using UnityEngine;
namespace UniVRM10
{
[CustomPropertyDrawer(typeof(VRM10SpringBoneCollider))]
public class VRM10SpringBoneColliderDrawer : PropertyDrawer
{
public override void OnGUI(Rect rect, SerializedProperty property, GUIContent label)
{
try
{
EditorGUI.ObjectField(rect, property, new GUIContent(((VRM10SpringBoneCollider)property.objectReferenceValue).GetIdentificationName()));
}
catch
{
EditorGUI.ObjectField(rect, property, new GUIContent());
}
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: fe667808067766449993409eec01bed5
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -13,7 +13,11 @@ namespace UniVRM10
GUI.backgroundColor = Color.cyan;
Repaint();
}
base.OnInspectorGUI();
var property = serializedObject.FindProperty("m_Script");
var script = (VRM10SpringBoneCollider)target;
EditorGUILayout.PropertyField(property, new GUIContent("Script (" + script.GetIdentificationName() + ")"));
DrawPropertiesExcluding(serializedObject, "m_Script");
serializedObject.ApplyModifiedProperties();
}
}
}

View File

@ -45,5 +45,33 @@ namespace UniVRM10
break;
}
}
public string GetIdentificationName()
{
var index = 0;
var count = 0;
var colliders = transform.GetComponents<VRM10SpringBoneCollider>();
foreach (var collider in colliders)
{
if (collider.ColliderType == ColliderType)
{
count++;
}
if (collider == this)
{
index = count;
}
}
if (count > 1)
{
return ColliderType.ToString() + index.ToString();
}
else
{
return ColliderType.ToString();
}
}
}
}