mirror of
https://github.com/vrm-c/UniVRM.git
synced 2026-09-11 21:38:56 -05:00
VRM10SpringBoneColliderEditor に PositionHandle と "Fit head-tail capsule" ボタン追加
This commit is contained in:
@@ -11,6 +11,11 @@ namespace UniVRM10
|
||||
Vrm10Instance _vrm;
|
||||
|
||||
SerializedProperty _script;
|
||||
SerializedProperty _colliderType;
|
||||
SerializedProperty _offset;
|
||||
SerializedProperty _tail;
|
||||
|
||||
static VRM10SpringBoneCollider s_selected;
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
@@ -21,6 +26,9 @@ namespace UniVRM10
|
||||
}
|
||||
|
||||
_script = serializedObject.FindProperty("m_Script");
|
||||
_colliderType = serializedObject.FindProperty(nameof(_target.ColliderType));
|
||||
_offset = serializedObject.FindProperty(nameof(_target.Offset));
|
||||
_tail = serializedObject.FindProperty(nameof(_target.Tail));
|
||||
}
|
||||
|
||||
public override void OnInspectorGUI()
|
||||
@@ -30,14 +38,13 @@ namespace UniVRM10
|
||||
EditorGUILayout.PropertyField(_script);
|
||||
}
|
||||
|
||||
var component = (VRM10SpringBoneCollider)target;
|
||||
switch (component.ColliderType)
|
||||
switch (_target.ColliderType)
|
||||
{
|
||||
case VRM10SpringBoneColliderTypes.Plane:
|
||||
// radius: x
|
||||
// tail: x
|
||||
// normal: o
|
||||
DrawPropertiesExcluding(serializedObject, "m_Script", nameof(component.Tail), nameof(component.Radius));
|
||||
DrawPropertiesExcluding(serializedObject, "m_Script", nameof(_target.Tail), nameof(_target.Radius));
|
||||
break;
|
||||
|
||||
case VRM10SpringBoneColliderTypes.Sphere:
|
||||
@@ -45,7 +52,7 @@ namespace UniVRM10
|
||||
// radius: o
|
||||
// tail: x
|
||||
// normal: x
|
||||
DrawPropertiesExcluding(serializedObject, nameof(component.Tail), nameof(component.Normal), "m_Script");
|
||||
DrawPropertiesExcluding(serializedObject, nameof(_target.Tail), nameof(_target.Normal), "m_Script");
|
||||
break;
|
||||
|
||||
case VRM10SpringBoneColliderTypes.Capsule:
|
||||
@@ -53,10 +60,31 @@ namespace UniVRM10
|
||||
// radius: o
|
||||
// tail: o
|
||||
// normal: x
|
||||
DrawPropertiesExcluding(serializedObject, nameof(component.Normal), "m_Script");
|
||||
DrawPropertiesExcluding(serializedObject, nameof(_target.Normal), "m_Script");
|
||||
break;
|
||||
}
|
||||
|
||||
EditorGUILayout.BeginHorizontal();
|
||||
{
|
||||
if (GUILayout.Button("Drag handle"))
|
||||
{
|
||||
s_selected = _target;
|
||||
}
|
||||
|
||||
if (_target.transform.childCount > 0)
|
||||
{
|
||||
if (GUILayout.Button("Fit head-tail capsule"))
|
||||
{
|
||||
_colliderType.enumValueFlag = (int)VRM10SpringBoneColliderTypes.Capsule;
|
||||
_offset.vector3Value = Vector3.zero;
|
||||
var tail = _target.transform.GetChild(0);
|
||||
_tail.vector3Value = _target.transform.worldToLocalMatrix.MultiplyPoint(
|
||||
tail.position);
|
||||
}
|
||||
}
|
||||
}
|
||||
EditorGUILayout.EndHorizontal();
|
||||
|
||||
if (serializedObject.ApplyModifiedProperties())
|
||||
{
|
||||
if (Application.isPlaying)
|
||||
@@ -69,5 +97,37 @@ namespace UniVRM10
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void OnSceneGUI()
|
||||
{
|
||||
HandleUtility.Repaint();
|
||||
|
||||
if (s_selected == _target)
|
||||
{
|
||||
var c = _target;
|
||||
Handles.matrix = c.transform.localToWorldMatrix;
|
||||
if (_target.ColliderType == VRM10SpringBoneColliderTypes.Capsule
|
||||
|| _target.ColliderType == VRM10SpringBoneColliderTypes.CapsuleInside)
|
||||
{
|
||||
EditorGUI.BeginChangeCheck();
|
||||
var newTargetPosition = Handles.PositionHandle(c.Tail, Quaternion.identity);
|
||||
if (EditorGUI.EndChangeCheck())
|
||||
{
|
||||
Undo.RecordObject(c, "collider");
|
||||
c.Tail = newTargetPosition;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
EditorGUI.BeginChangeCheck();
|
||||
var newTargetPosition = Handles.PositionHandle(c.Offset, Quaternion.identity);
|
||||
if (EditorGUI.EndChangeCheck())
|
||||
{
|
||||
Undo.RecordObject(c, "collider");
|
||||
c.Offset = newTargetPosition;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -68,10 +68,6 @@ namespace UniVRM10
|
||||
|
||||
if (s_collider is VRM10SpringBoneCollider c)
|
||||
{
|
||||
// var t = p.transform;
|
||||
// Handles.color = Color.green;
|
||||
// Handles.SphereHandleCap(t.GetInstanceID(), t.position, t.rotation, p.Radius * 2, EventType.Repaint);
|
||||
|
||||
EditorGUI.BeginChangeCheck();
|
||||
Handles.matrix = c.transform.localToWorldMatrix;
|
||||
var newTargetPosition = Handles.PositionHandle(c.Offset, Quaternion.identity);
|
||||
|
||||
Reference in New Issue
Block a user