diff --git a/Assets/VRM10/Editor/Components/SpringBone/SpringBoneEditor.cs b/Assets/VRM10/Editor/Components/SpringBone/SpringBoneEditor.cs
index a06fe694f..36765b466 100644
--- a/Assets/VRM10/Editor/Components/SpringBone/SpringBoneEditor.cs
+++ b/Assets/VRM10/Editor/Components/SpringBone/SpringBoneEditor.cs
@@ -27,6 +27,8 @@ namespace UniVRM10
s_treeView = null;
}
+ public static MonoBehaviour Active;
+
///
/// 2D の GUI 描画
///
@@ -50,7 +52,7 @@ namespace UniVRM10
var tree = GetTree(target, so);
if (tree != null && target != null)
{
- tree.Draw3D(target.SpringBone);
+ Active = tree.Draw3D(target.SpringBone);
}
}
}
diff --git a/Assets/VRM10/Editor/Components/SpringBone/SpringBoneTreeView.cs b/Assets/VRM10/Editor/Components/SpringBone/SpringBoneTreeView.cs
index 00072502f..f1de1080d 100644
--- a/Assets/VRM10/Editor/Components/SpringBone/SpringBoneTreeView.cs
+++ b/Assets/VRM10/Editor/Components/SpringBone/SpringBoneTreeView.cs
@@ -116,8 +116,17 @@ namespace UniVRM10
Color s_selectedColor = new Color(0.5f, 0, 0, 0.5f);
Color s_Color = new Color(0.6f, 0.6f, 0.6f, 0.5f);
- public void Draw3D(Vrm10InstanceSpringBone springBone)
+ Vrm10InstanceSpringBone last = null;
+ MonoBehaviour Active = null;
+
+ public MonoBehaviour Draw3D(Vrm10InstanceSpringBone springBone)
{
+ if (springBone != last)
+ {
+ Active = null;
+ last = springBone;
+ }
+
if (_selected is SelectedColliderGroupGUI colliderGroup)
{
// colliderGroup.Draw3D();
@@ -127,14 +136,15 @@ namespace UniVRM10
// TODO
}
+ MonoBehaviour newActive = null;
foreach (var group in springBone.ColliderGroups)
{
foreach (var collider in group.Colliders)
{
- var color = collider.gameObject == Selection.activeObject ? s_selectedColor : s_Color;
+ var color = collider == Active ? s_selectedColor : s_Color;
if (DrawCollider(collider, color))
{
- Selection.activeObject = collider.gameObject;
+ newActive = collider;
}
}
}
@@ -144,13 +154,44 @@ namespace UniVRM10
{
var head = spring.Joints[i - 1];
var tail = spring.Joints[i];
- var color = tail.gameObject == Selection.activeObject ? s_selectedColor : s_Color;
+ var color = head == Active ? s_selectedColor : s_Color;
if (DrawJoint(head, tail, color))
{
- Selection.activeObject = tail.gameObject;
+ newActive = head;
}
}
}
+
+ if (Active is VRM10SpringBoneCollider activeCollider)
+ {
+ EditorGUI.BeginChangeCheck();
+ Handles.matrix = activeCollider.transform.localToWorldMatrix;
+ var offset = Handles.PositionHandle(activeCollider.Offset, Quaternion.identity);
+ var tail = Vector3.zero;
+ if (activeCollider.ColliderType == VRM10SpringBoneColliderTypes.Capsule)
+ {
+ tail = Handles.PositionHandle(activeCollider.Tail, Quaternion.identity);
+ }
+ var offsetChanged = EditorGUI.EndChangeCheck();
+ if (offsetChanged)
+ {
+ // apply
+ Undo.RecordObject(activeCollider, "activeCollider");
+ activeCollider.Offset = offset;
+ if (activeCollider.ColliderType == VRM10SpringBoneColliderTypes.Capsule)
+ {
+ activeCollider.Tail = tail;
+ }
+ }
+ }
+
+ if (newActive != null)
+ {
+ Selection.activeObject = newActive.gameObject;
+ Active = newActive;
+ }
+
+ return Active;
}
static bool IsLeftDown()
diff --git a/Assets/VRM10/Editor/Components/VRM10Window.cs b/Assets/VRM10/Editor/Components/VRM10Window.cs
index f7aca7c2b..331db7550 100644
--- a/Assets/VRM10/Editor/Components/VRM10Window.cs
+++ b/Assets/VRM10/Editor/Components/VRM10Window.cs
@@ -71,49 +71,14 @@ namespace UniVRM10
Transform m_head;
- // public IVrm10Constraint[] m_constraints;
-
ScrollView m_scrollView = new ScrollView();
- // enum VRMSceneUI
- // {
- // Constraints,
- // SpringBone,
- // }
- // static VRMSceneUI s_ui = default;
- // static string[] s_selection;
- // static string[] Selection
- // {
- // get
- // {
- // if (s_selection == null)
- // {
- // s_selection = Enum.GetNames(typeof(VRMSceneUI));
- // }
- // return s_selection;
- // }
- // }
-
///
/// public entry point
///
///
void OnSceneGUI(SceneView sceneView)
{
- // switch (s_ui)
- // {
- // case VRMSceneUI.Constraints:
- // Tools.hidden = false;
- // break;
-
- // case VRMSceneUI.SpringBone:
- // Tools.hidden = true;
- // SpringBoneEditor.Draw3D(Root, m_so);
- // break;
-
- // default:
- // throw new NotImplementedException();
- // }
Tools.hidden = true;
SpringBoneEditor.Draw3D(Root, m_so);
}
@@ -133,18 +98,17 @@ namespace UniVRM10
}
}
+ // Root
Root = (Vrm10Instance)EditorGUILayout.ObjectField("vrm1", Root, typeof(Vrm10Instance), true);
if (Root == null)
{
return;
}
- // var ui = (VRMSceneUI)GUILayout.SelectionGrid((int)s_ui, Selection, 3);
- // if (s_ui != ui)
- // {
- // s_ui = ui;
- // SceneView.RepaintAll();
- // }
+ // active
+ EditorGUI.BeginDisabledGroup(true);
+ EditorGUILayout.ObjectField("joint or collider", SpringBoneEditor.Active, typeof(MonoBehaviour), true);
+ EditorGUI.EndDisabledGroup();
if (m_so == null)
{
@@ -156,44 +120,9 @@ namespace UniVRM10
}
m_so.Update();
- // switch (s_ui)
- // {
- // case VRMSceneUI.Constraints:
- // m_scrollView.Draw(this.position.y, DrawConstraints, Repaint);
- // break;
-
- // case VRMSceneUI.SpringBone:
- // SpringBoneEditor.Draw2D(Root, m_so);
- // break;
-
- // default:
- // throw new NotImplementedException();
- // }
SpringBoneEditor.Draw2D(Root, m_so);
m_so.ApplyModifiedProperties();
}
-
- // void DrawConstraints()
- // {
- // if (Root != null)
- // {
- // if (m_constraints == null)
- // {
- // m_constraints = Root.GetComponentsInChildren();
- // }
- // }
-
- // using (new EditorGUI.DisabledScope(true))
- // {
- // if (m_constraints != null)
- // {
- // foreach (var c in m_constraints)
- // {
- // EditorGUILayout.ObjectField(c.ConstraintTarget, typeof(MonoBehaviour), true);
- // }
- // }
- // }
- // }
}
}