1111using Microsoft . MixedReality . Toolkit . SDK . UX . Interactable . Profile ;
1212using Microsoft . MixedReality . Toolkit . SDK . UX . Interactable . States ;
1313using Microsoft . MixedReality . Toolkit . SDK . UX . Interactable . Themes ;
14+ using System ;
1415using System . Collections ;
1516using System . Collections . Generic ;
1617using UnityEngine ;
@@ -41,7 +42,7 @@ public class Interactable : MonoBehaviour, IMixedRealityFocusHandler, IMixedReal
4142 /// </summary>
4243 private static IMixedRealityInputSystem inputSystem = null ;
4344 protected static IMixedRealityInputSystem InputSystem => inputSystem ?? ( inputSystem = MixedRealityToolkit . Instance . GetService < IMixedRealityInputSystem > ( ) ) ;
44-
45+
4546 // list of pointers
4647 protected List < IMixedRealityPointer > pointers = new List < IMixedRealityPointer > ( ) ;
4748 public List < IMixedRealityPointer > Focusers => pointers ;
@@ -156,23 +157,25 @@ public void RemoveHandler(IInteractableHandler handler)
156157 }
157158
158159 #region InspectorHelpers
159- /// <summary>
160- /// Gets a list of input actions, used by the inspector
161- /// </summary>
162- /// <returns></returns>
163- public static string [ ] GetInputActions ( )
160+ public static bool TryGetInputActions ( out string [ ] descriptionsArray )
164161 {
162+ if ( ! MixedRealityToolkit . IsInitialized || ! MixedRealityToolkit . HasActiveProfile )
163+ {
164+ descriptionsArray = null ;
165+ return false ;
166+ }
167+
165168 MixedRealityInputAction [ ] actions = MixedRealityToolkit . Instance . ActiveProfile . InputSystemProfile . InputActionsProfile . InputActions ;
166169
167- List < string > list = new List < string > ( ) ;
170+ descriptionsArray = new string [ actions . Length ] ;
168171 for ( int i = 0 ; i < actions . Length ; i ++ )
169172 {
170- list . Add ( actions [ i ] . Description ) ;
173+ descriptionsArray [ i ] = actions [ i ] . Description ;
171174 }
172175
173- return list . ToArray ( ) ;
176+ return true ;
174177 }
175-
178+
176179 /// <summary>
177180 /// Returns a list of states assigned to the Interactable
178181 /// </summary>
@@ -183,7 +186,7 @@ public State[] GetStates()
183186 {
184187 return States . GetStates ( ) ;
185188 }
186-
189+
187190 return new State [ 0 ] ;
188191 }
189192 #endregion InspectorHelpers
@@ -208,17 +211,17 @@ private void OnEnable()
208211
209212 SetupVoiceCommand ( ) ;
210213 }
211-
214+
212215 private void OnDisable ( )
213216 {
214217 if ( IsGlobal )
215218 {
216219 InputSystem . Unregister ( gameObject ) ;
217220 }
218-
221+
219222 StopVoiceCommand ( ) ;
220223 }
221-
224+
222225 protected virtual void Update ( )
223226 {
224227 if ( rollOffTimer < rollOffTime && HasPress )
@@ -289,7 +292,7 @@ protected virtual void SetupStates()
289292 protected virtual void SetupEvents ( )
290293 {
291294 InteractableEvent . EventLists lists = InteractableEvent . GetEventTypes ( ) ;
292-
295+
293296 for ( int i = 0 ; i < Events . Count ; i ++ )
294297 {
295298 Events [ i ] . Receiver = InteractableEvent . GetReceiver ( Events [ i ] , lists ) ;
@@ -323,7 +326,7 @@ protected virtual void SetupThemes()
323326 InteractableThemePropertySettings settings = theme . Settings [ n ] ;
324327
325328 settings . Theme = InteractableProfileItem . GetTheme ( settings , Profiles [ i ] . Target , lists ) ;
326-
329+
327330 // add themes to theme list based on dimension
328331 if ( j == dimensionIndex )
329332 {
@@ -332,7 +335,7 @@ protected virtual void SetupThemes()
332335
333336 tempSettings . Add ( settings ) ;
334337 }
335-
338+
336339 themeSettings . Settings = tempSettings ;
337340 themeSettingsList . Add ( themeSettings ) ;
338341 }
@@ -344,7 +347,7 @@ protected virtual void SetupThemes()
344347 }
345348
346349 #endregion InteractableInitiation
347-
350+
348351 #region SetButtonStates
349352
350353 /// <summary>
@@ -364,7 +367,7 @@ public int GetStateValue(InteractableStates.InteractableStateEnum state)
364367 public virtual void SetFocus ( bool focus )
365368 {
366369 HasFocus = focus ;
367- if ( ! focus && HasPress )
370+ if ( ! focus && HasPress )
368371 {
369372 rollOffTimer = 0 ;
370373 }
@@ -376,14 +379,14 @@ public virtual void SetFocus(bool focus)
376379 StateManager . SetStateValue ( InteractableStates . InteractableStateEnum . Focus , focus ? 1 : 0 ) ;
377380 UpdateState ( ) ;
378381 }
379-
382+
380383 public virtual void SetPress ( bool press )
381384 {
382385 HasPress = press ;
383386 StateManager . SetStateValue ( InteractableStates . InteractableStateEnum . Pressed , press ? 1 : 0 ) ;
384387 UpdateState ( ) ;
385388 }
386-
389+
387390 public virtual void SetDisabled ( bool disabled )
388391 {
389392 IsDisabled = disabled ;
@@ -546,7 +549,7 @@ public void OnFocusExit(FocusEventData eventData)
546549 #endregion MixedRealityFocusHandlers
547550
548551 #region MixedRealityPointerHandlers
549-
552+
550553 /// <summary>
551554 /// pointer up event has fired
552555 /// </summary>
@@ -692,7 +695,7 @@ public void OnInputDown(InputEventData eventData)
692695 {
693696 return ;
694697 }
695-
698+
696699 if ( StateManager != null )
697700 {
698701 if ( eventData != null && ShouldListen ( eventData . MixedRealityInputAction ) && ( eventData . MixedRealityInputAction != pointerInputAction || pointerInputAction == MixedRealityInputAction . None ) )
@@ -786,8 +789,8 @@ protected void IncreaseDimensionIndex()
786789 {
787790 dimensionIndex = 0 ;
788791 }
789-
790- if ( currentIndex != dimensionIndex )
792+
793+ if ( currentIndex != dimensionIndex )
791794 {
792795 FilterThemesByDimensions ( ) ;
793796 forceUpdate = true ;
@@ -850,7 +853,7 @@ protected virtual bool CanInteract()
850853 return false ;
851854 }
852855
853- if ( Dimensions > 1 && ( ( dimensionIndex != Dimensions - 1 & ! CanSelect ) || ( dimensionIndex == Dimensions - 1 & ! CanDeselect ) ) )
856+ if ( Dimensions > 1 && ( ( dimensionIndex != Dimensions - 1 & ! CanSelect ) || ( dimensionIndex == Dimensions - 1 & ! CanDeselect ) ) )
854857 {
855858 return false ;
856859 }
@@ -914,9 +917,10 @@ protected void StartGlobalVisual(bool voiceCommand = false)
914917 protected IEnumerator GlobalVisualReset ( float time )
915918 {
916919 yield return new WaitForSeconds ( time ) ;
917-
920+
918921 StateManager . SetStateValue ( InteractableStates . InteractableStateEnum . VoiceCommand , 0 ) ;
919- if ( ! HasFocus ) {
922+ if ( ! HasFocus )
923+ {
920924 StateManager . SetStateValue ( InteractableStates . InteractableStateEnum . Focus , 0 ) ;
921925 }
922926
@@ -955,7 +959,7 @@ public void OnSpeechKeywordRecognized(SpeechEventData eventData)
955959 if ( Enabled && ShouldListen ( eventData . MixedRealityInputAction ) )
956960 {
957961 StartGlobalVisual ( true ) ;
958-
962+
959963 IncreaseDimensionIndex ( ) ;
960964 SendVoiceCommands ( eventData . RecognizedText , 0 , 1 ) ;
961965
@@ -972,15 +976,15 @@ protected void SetupVoiceCommand()
972976#if UNITY_STANDALONE_WIN || UNITY_WSA || UNITY_EDITOR_WIN
973977 if ( ! string . IsNullOrEmpty ( VoiceCommand ) && VoiceCommand . Length > 2 )
974978 {
975- voiceCommands = new string [ ] { VoiceCommand } ;
979+ voiceCommands = new string [ ] { VoiceCommand } ;
976980 if ( VoiceCommand . IndexOf ( "," ) > - 1 )
977981 {
978982 voiceCommands = VoiceCommand . Split ( ',' ) ;
979983 }
980984
981985 recognitionConfidenceLevel = MixedRealityToolkit . Instance . ActiveProfile . InputSystemProfile . SpeechCommandsProfile . SpeechRecognitionConfidenceLevel ;
982986
983- if ( keywordRecognizer == null )
987+ if ( keywordRecognizer == null )
984988 {
985989 keywordRecognizer = new KeywordRecognizer ( voiceCommands , ( ConfidenceLevel ) recognitionConfidenceLevel ) ;
986990 keywordRecognizer . OnPhraseRecognized += KeywordRecognizer_OnPhraseRecognized ;
@@ -1015,7 +1019,7 @@ protected void KeywordRecognizer_OnPhraseRecognized(PhraseRecognizedEventArgs ar
10151019 {
10161020 if ( args . text == VoiceCommand && ( ! RequiresFocus || HasFocus ) && CanInteract ( ) )
10171021 {
1018-
1022+
10191023 if ( CanInteract ( ) )
10201024 {
10211025 StartGlobalVisual ( true ) ;
@@ -1066,11 +1070,11 @@ protected void SendVoiceCommands(string command, int index, int length)
10661070 /// <returns></returns>
10671071 protected int GetVoiceCommandIndex ( string command )
10681072 {
1069- if ( voiceCommands . Length > 1 )
1073+ if ( voiceCommands . Length > 1 )
10701074 {
10711075 for ( int i = 0 ; i < voiceCommands . Length ; i ++ )
10721076 {
1073- if ( command == voiceCommands [ i ] )
1077+ if ( command == voiceCommands [ i ] )
10741078 {
10751079 return i ;
10761080 }
@@ -1079,7 +1083,7 @@ protected int GetVoiceCommandIndex(string command)
10791083
10801084 return 0 ;
10811085 }
1082-
1086+
10831087 #endregion VoiceCommands
10841088
10851089 }
0 commit comments