22// Licensed under the MIT License. See LICENSE in the project root for license information.
33
44using Microsoft . MixedReality . Toolkit . Core . Definitions ;
5+ using Microsoft . MixedReality . Toolkit . Core . Definitions . Devices ;
56using Microsoft . MixedReality . Toolkit . Core . Definitions . InputSystem ;
67using Microsoft . MixedReality . Toolkit . Core . Managers ;
8+ using System ;
9+ using System . Collections . Generic ;
710using System . Linq ;
811using UnityEditor ;
912using UnityEngine ;
@@ -19,16 +22,19 @@ public class MixedRealityGesturesProfileInspector : MixedRealityBaseConfiguratio
1922 private static readonly GUIContent GestureTypeContent = new GUIContent ( "Gesture Type" , "The type of Gesture that will trigger the action." ) ;
2023 private static readonly GUIContent ActionContent = new GUIContent ( "Action" , "The action to trigger when a Gesture is recognized." ) ;
2124
22- private static GUIContent [ ] actionLabels ;
23- private static int [ ] actionIds ;
24-
2525 private SerializedProperty gestures ;
2626 private SerializedProperty windowsManipulationGestureSettings ;
2727 private SerializedProperty useRailsNavigation ;
2828 private SerializedProperty windowsNavigationGestureSettings ;
2929 private SerializedProperty windowsRailsNavigationGestures ;
3030 private SerializedProperty windowsGestureAutoStart ;
3131
32+ private MixedRealityGesturesProfile thisProfile ;
33+ private static GUIContent [ ] allGestureLabels ;
34+ private static int [ ] allGestureIds ;
35+ private static GUIContent [ ] actionLabels ;
36+ private static int [ ] actionIds ;
37+
3238 private void OnEnable ( )
3339 {
3440 if ( ! CheckMixedRealityManager ( false ) ) { return ; }
@@ -39,13 +45,42 @@ private void OnEnable()
3945 windowsNavigationGestureSettings = serializedObject . FindProperty ( "navigationGestures" ) ;
4046 windowsRailsNavigationGestures = serializedObject . FindProperty ( "railsNavigationGestures" ) ;
4147 windowsGestureAutoStart = serializedObject . FindProperty ( "windowsGestureAutoStart" ) ;
48+ thisProfile = target as MixedRealityGesturesProfile ;
49+ Debug . Assert ( thisProfile != null ) ;
4250
4351 if ( MixedRealityManager . Instance . ActiveProfile . IsInputSystemEnabled &&
4452 MixedRealityManager . Instance . ActiveProfile . InputSystemProfile . InputActionsProfile != null )
4553 {
46- actionLabels = MixedRealityManager . Instance . ActiveProfile . InputSystemProfile . InputActionsProfile . InputActions . Select ( action => new GUIContent ( action . Description ) ) . Prepend ( new GUIContent ( "None" ) ) . ToArray ( ) ;
47- actionIds = MixedRealityManager . Instance . ActiveProfile . InputSystemProfile . InputActionsProfile . InputActions . Select ( action => ( int ) action . Id ) . Prepend ( 0 ) . ToArray ( ) ;
54+ actionLabels = MixedRealityManager . Instance . ActiveProfile . InputSystemProfile . InputActionsProfile . InputActions
55+ . Select ( action => new GUIContent ( action . Description ) )
56+ . Prepend ( new GUIContent ( "None" ) ) . ToArray ( ) ;
57+ actionIds = MixedRealityManager . Instance . ActiveProfile . InputSystemProfile . InputActionsProfile . InputActions
58+ . Select ( action => ( int ) action . Id )
59+ . Prepend ( 0 ) . ToArray ( ) ;
60+ }
61+
62+ UpdateGestureLabels ( ) ;
63+ }
64+
65+ private void UpdateGestureLabels ( )
66+ {
67+ var allGestureTypeNames = Enum . GetNames ( typeof ( GestureInputType ) ) ;
68+
69+ var tempIds = new List < int > ( ) ;
70+ var tempContent = new List < GUIContent > ( ) ;
71+
72+ for ( int i = 0 ; i < allGestureTypeNames . Length ; i ++ )
73+ {
74+ if ( allGestureTypeNames [ i ] . Equals ( "None" ) ||
75+ thisProfile . Gestures . All ( mapping => ! allGestureTypeNames [ i ] . Equals ( mapping . GestureType . ToString ( ) ) ) )
76+ {
77+ tempContent . Add ( new GUIContent ( allGestureTypeNames [ i ] ) ) ;
78+ tempIds . Add ( i ) ;
79+ }
4880 }
81+
82+ allGestureIds = tempIds . ToArray ( ) ;
83+ allGestureLabels = tempContent . ToArray ( ) ;
4984 }
5085
5186 public override void OnInspectorGUI ( )
@@ -101,7 +136,7 @@ public override void OnInspectorGUI()
101136 serializedObject . ApplyModifiedProperties ( ) ;
102137 }
103138
104- private static void RenderList ( SerializedProperty list )
139+ private void RenderList ( SerializedProperty list )
105140 {
106141 EditorGUILayout . Space ( ) ;
107142 GUILayout . BeginVertical ( ) ;
@@ -112,8 +147,8 @@ private static void RenderList(SerializedProperty list)
112147 var speechCommand = list . GetArrayElementAtIndex ( list . arraySize - 1 ) ;
113148 var keyword = speechCommand . FindPropertyRelative ( "description" ) ;
114149 keyword . stringValue = string . Empty ;
115- var keyCode = speechCommand . FindPropertyRelative ( "gestureType" ) ;
116- keyCode . intValue = ( int ) KeyCode . None ;
150+ var gestureType = speechCommand . FindPropertyRelative ( "gestureType" ) ;
151+ gestureType . intValue = ( int ) GestureInputType . None ;
117152 var action = speechCommand . FindPropertyRelative ( "action" ) ;
118153 var actionId = action . FindPropertyRelative ( "id" ) ;
119154 actionId . intValue = 0 ;
@@ -129,6 +164,7 @@ private static void RenderList(SerializedProperty list)
129164 {
130165 EditorGUILayout . HelpBox ( "Define a new Gesture." , MessageType . Warning ) ;
131166 GUILayout . EndVertical ( ) ;
167+ UpdateGestureLabels ( ) ;
132168 return ;
133169 }
134170
@@ -149,14 +185,37 @@ private static void RenderList(SerializedProperty list)
149185 EditorGUILayout . BeginHorizontal ( ) ;
150186 SerializedProperty gesture = list . GetArrayElementAtIndex ( i ) ;
151187 var keyword = gesture . FindPropertyRelative ( "description" ) ;
152- EditorGUILayout . PropertyField ( keyword , GUIContent . none , GUILayout . ExpandWidth ( true ) ) ;
153188 var gestureType = gesture . FindPropertyRelative ( "gestureType" ) ;
154- EditorGUILayout . PropertyField ( gestureType , GUIContent . none , GUILayout . Width ( 80f ) ) ;
155189 var action = gesture . FindPropertyRelative ( "action" ) ;
156190 var actionId = action . FindPropertyRelative ( "id" ) ;
157191 var actionDescription = action . FindPropertyRelative ( "description" ) ;
158192 var actionConstraint = action . FindPropertyRelative ( "axisConstraint" ) ;
159193
194+ EditorGUILayout . PropertyField ( keyword , GUIContent . none , GUILayout . ExpandWidth ( true ) ) ;
195+
196+ Debug . Assert ( allGestureLabels . Length == allGestureIds . Length ) ;
197+
198+ var gestureLabels = new GUIContent [ allGestureLabels . Length + 1 ] ;
199+ var gestureIds = new int [ allGestureIds . Length + 1 ] ;
200+
201+ gestureLabels [ 0 ] = new GUIContent ( ( ( GestureInputType ) gestureType . intValue ) . ToString ( ) ) ;
202+ gestureIds [ 0 ] = gestureType . intValue ;
203+
204+ for ( int j = 0 ; j < allGestureLabels . Length ; j ++ )
205+ {
206+ gestureLabels [ j + 1 ] = allGestureLabels [ j ] ;
207+ gestureIds [ j + 1 ] = allGestureIds [ j ] ;
208+ }
209+
210+ EditorGUI . BeginChangeCheck ( ) ;
211+ gestureType . intValue = EditorGUILayout . IntPopup ( GUIContent . none , gestureType . intValue , gestureLabels , gestureIds , GUILayout . Width ( 80f ) ) ;
212+
213+ if ( EditorGUI . EndChangeCheck ( ) )
214+ {
215+ serializedObject . ApplyModifiedProperties ( ) ;
216+ UpdateGestureLabels ( ) ;
217+ }
218+
160219 EditorGUI . BeginChangeCheck ( ) ;
161220 actionId . intValue = EditorGUILayout . IntPopup ( GUIContent . none , actionId . intValue , actionLabels , actionIds , GUILayout . Width ( 64f ) ) ;
162221
@@ -165,11 +224,14 @@ private static void RenderList(SerializedProperty list)
165224 MixedRealityInputAction inputAction = actionId . intValue == 0 ? MixedRealityInputAction . None : MixedRealityManager . Instance . ActiveProfile . InputSystemProfile . InputActionsProfile . InputActions [ actionId . intValue - 1 ] ;
166225 actionDescription . stringValue = inputAction . Description ;
167226 actionConstraint . enumValueIndex = ( int ) inputAction . AxisConstraint ;
227+ serializedObject . ApplyModifiedProperties ( ) ;
168228 }
169229
170230 if ( GUILayout . Button ( MinusButtonContent , EditorStyles . miniButtonRight , GUILayout . Width ( 24f ) ) )
171231 {
172232 list . DeleteArrayElementAtIndex ( i ) ;
233+ serializedObject . ApplyModifiedProperties ( ) ;
234+ UpdateGestureLabels ( ) ;
173235 }
174236
175237 EditorGUILayout . EndHorizontal ( ) ;
0 commit comments