Skip to content

Commit 4caf9f2

Browse files
Constraint discoverability
1 parent b444145 commit 4caf9f2

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

Assets/MixedRealityToolkit.SDK/Inspectors/Experimental/UX/ObjectManipulator/ObjectManipulatorInspector.cs

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,13 @@
44
//
55

66
using Microsoft.MixedReality.Toolkit.Experimental.UI;
7+
using Microsoft.MixedReality.Toolkit.UI;
78
using Microsoft.MixedReality.Toolkit.Utilities;
9+
using System;
10+
using System.Linq;
811
using UnityEditor;
912
using UnityEngine;
13+
using UnityEngine.UI;
1014

1115
namespace Microsoft.MixedReality.Toolkit.Experimental.Editor
1216
{
@@ -41,6 +45,7 @@ public class ObjectManipulatorInspector : UnityEditor.Editor
4145

4246
bool oneHandedFoldout = true;
4347
bool twoHandedFoldout = true;
48+
bool constraintsFoldout = true;
4449
bool physicsFoldout = true;
4550
bool smoothingFoldout = true;
4651
bool eventsFoldout = true;
@@ -120,6 +125,45 @@ public override void OnInspectorGUI()
120125
var mh = (ObjectManipulator)target;
121126
var rb = mh.HostTransform.GetComponent<Rigidbody>();
122127

128+
EditorGUILayout.Space();
129+
constraintsFoldout = EditorGUILayout.Foldout(constraintsFoldout, "Constraints", true);
130+
131+
if (constraintsFoldout)
132+
{
133+
if (EditorGUILayout.DropdownButton(new GUIContent("Add Constraint"), FocusType.Keyboard))
134+
{
135+
// create the menu and add items to it
136+
GenericMenu menu = new GenericMenu();
137+
138+
var type = typeof(TransformConstraint);
139+
var types = AppDomain.CurrentDomain.GetAssemblies()
140+
.SelectMany(s => s.GetTypes())
141+
.Where(p => type.IsAssignableFrom(p));
142+
143+
foreach (var derivedType in types)
144+
{
145+
menu.AddItem(new GUIContent(derivedType.Name), false, t => mh.gameObject.AddComponent((Type)t), derivedType);
146+
}
147+
148+
menu.ShowAsContext();
149+
}
150+
151+
var constraints = mh.GetComponents<TransformConstraint>();
152+
153+
foreach (var constraint in constraints)
154+
{
155+
EditorGUILayout.BeginHorizontal();
156+
string constraintName = constraint.GetType().Name;
157+
EditorGUILayout.LabelField(constraintName);
158+
if (GUILayout.Button("Go to component"))
159+
{
160+
Debug.Log($"Highlighting {ObjectNames.NicifyVariableName(constraintName)} (Script)");
161+
Highlighter.Highlight("Inspector", $"{ObjectNames.NicifyVariableName(constraintName)} (Script)");
162+
}
163+
EditorGUILayout.EndHorizontal();
164+
}
165+
}
166+
123167
EditorGUILayout.Space();
124168
physicsFoldout = EditorGUILayout.Foldout(physicsFoldout, "Physics", true);
125169

0 commit comments

Comments
 (0)