mirror of
https://github.com/vrm-c/UniVRM.git
synced 2026-05-15 23:20:10 -05:00
82 lines
2.3 KiB
C#
82 lines
2.3 KiB
C#
using System;
|
|
using System.Linq;
|
|
using UnityEditor;
|
|
using UnityEditor.UIElements;
|
|
using UnityEngine;
|
|
using UnityEngine.UIElements;
|
|
|
|
|
|
namespace UniVRM10
|
|
{
|
|
[CustomEditor(typeof(VRM10SpringBoneColliderGroup))]
|
|
class VRM10SpringBoneColliderGroupEditor : Editor
|
|
{
|
|
ListView m_colliders;
|
|
|
|
static VRM10SpringBoneCollider s_collider;
|
|
|
|
public override VisualElement CreateInspectorGUI()
|
|
{
|
|
var root = new VisualElement();
|
|
|
|
// root.TrackSerializedObjectValue(serializedObject, OnValueChanged);
|
|
|
|
root.Bind(serializedObject);
|
|
|
|
{
|
|
var s = new PropertyField { bindingPath = "m_Script" };
|
|
s.SetEnabled(false);
|
|
root.Add(s);
|
|
}
|
|
|
|
|
|
root.Add(new PropertyField { bindingPath = nameof(VRM10SpringBoneColliderGroup.Name) });
|
|
|
|
{
|
|
m_colliders = new ListView
|
|
{
|
|
bindingPath = nameof(VRM10SpringBoneColliderGroup.Colliders)
|
|
};
|
|
m_colliders.selectionChanged += (e) =>
|
|
{
|
|
var item = (SerializedProperty)e.FirstOrDefault();
|
|
if (item == null)
|
|
{
|
|
s_collider = null;
|
|
}
|
|
else
|
|
{
|
|
s_collider = (VRM10SpringBoneCollider)item.objectReferenceValue;
|
|
}
|
|
};
|
|
m_colliders.showAddRemoveFooter = true;
|
|
m_colliders.showFoldoutHeader = true;
|
|
m_colliders.headerTitle = "Colliders";
|
|
root.Add(m_colliders);
|
|
}
|
|
|
|
return root;
|
|
}
|
|
|
|
public void OnSceneGUI()
|
|
{
|
|
HandleUtility.Repaint();
|
|
if (m_colliders == null)
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (s_collider is VRM10SpringBoneCollider c)
|
|
{
|
|
EditorGUI.BeginChangeCheck();
|
|
Handles.matrix = c.transform.localToWorldMatrix;
|
|
var newTargetPosition = Handles.PositionHandle(c.Offset, Quaternion.identity);
|
|
if (EditorGUI.EndChangeCheck())
|
|
{
|
|
Undo.RecordObject(c, "collider");
|
|
c.Offset = newTargetPosition;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
} |