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 )
@@ -320,7 +323,6 @@ protected virtual void SetupThemes()
320323 InteractableThemePropertySettings settings = theme . Settings [ n ] ;
321324
322325 settings . Theme = InteractableProfileItem . GetTheme ( settings , Profiles [ i ] . Target ) ;
323-
324326 // add themes to theme list based on dimension
325327 if ( j == dimensionIndex )
326328 {
@@ -329,7 +331,7 @@ protected virtual void SetupThemes()
329331
330332 tempSettings . Add ( settings ) ;
331333 }
332-
334+
333335 themeSettings . Settings = tempSettings ;
334336 themeSettingsList . Add ( themeSettings ) ;
335337 }
@@ -341,7 +343,7 @@ protected virtual void SetupThemes()
341343 }
342344
343345 #endregion InteractableInitiation
344-
346+
345347 #region SetButtonStates
346348
347349 /// <summary>
@@ -361,7 +363,7 @@ public int GetStateValue(InteractableStates.InteractableStateEnum state)
361363 public virtual void SetFocus ( bool focus )
362364 {
363365 HasFocus = focus ;
364- if ( ! focus && HasPress )
366+ if ( ! focus && HasPress )
365367 {
366368 rollOffTimer = 0 ;
367369 }
@@ -373,14 +375,14 @@ public virtual void SetFocus(bool focus)
373375 StateManager . SetStateValue ( InteractableStates . InteractableStateEnum . Focus , focus ? 1 : 0 ) ;
374376 UpdateState ( ) ;
375377 }
376-
378+
377379 public virtual void SetPress ( bool press )
378380 {
379381 HasPress = press ;
380382 StateManager . SetStateValue ( InteractableStates . InteractableStateEnum . Pressed , press ? 1 : 0 ) ;
381383 UpdateState ( ) ;
382384 }
383-
385+
384386 public virtual void SetDisabled ( bool disabled )
385387 {
386388 IsDisabled = disabled ;
@@ -543,7 +545,7 @@ public void OnFocusExit(FocusEventData eventData)
543545 #endregion MixedRealityFocusHandlers
544546
545547 #region MixedRealityPointerHandlers
546-
548+
547549 /// <summary>
548550 /// pointer up event has fired
549551 /// </summary>
@@ -689,7 +691,7 @@ public void OnInputDown(InputEventData eventData)
689691 {
690692 return ;
691693 }
692-
694+
693695 if ( StateManager != null )
694696 {
695697 if ( eventData != null && ShouldListen ( eventData . MixedRealityInputAction ) && ( eventData . MixedRealityInputAction != pointerInputAction || pointerInputAction == MixedRealityInputAction . None ) )
@@ -783,8 +785,8 @@ protected void IncreaseDimensionIndex()
783785 {
784786 dimensionIndex = 0 ;
785787 }
786-
787- if ( currentIndex != dimensionIndex )
788+
789+ if ( currentIndex != dimensionIndex )
788790 {
789791 FilterThemesByDimensions ( ) ;
790792 forceUpdate = true ;
@@ -847,7 +849,7 @@ protected virtual bool CanInteract()
847849 return false ;
848850 }
849851
850- if ( Dimensions > 1 && ( ( dimensionIndex != Dimensions - 1 & ! CanSelect ) || ( dimensionIndex == Dimensions - 1 & ! CanDeselect ) ) )
852+ if ( Dimensions > 1 && ( ( dimensionIndex != Dimensions - 1 & ! CanSelect ) || ( dimensionIndex == Dimensions - 1 & ! CanDeselect ) ) )
851853 {
852854 return false ;
853855 }
@@ -911,9 +913,10 @@ protected void StartGlobalVisual(bool voiceCommand = false)
911913 protected IEnumerator GlobalVisualReset ( float time )
912914 {
913915 yield return new WaitForSeconds ( time ) ;
914-
916+
915917 StateManager . SetStateValue ( InteractableStates . InteractableStateEnum . VoiceCommand , 0 ) ;
916- if ( ! HasFocus ) {
918+ if ( ! HasFocus )
919+ {
917920 StateManager . SetStateValue ( InteractableStates . InteractableStateEnum . Focus , 0 ) ;
918921 }
919922
@@ -952,7 +955,7 @@ public void OnSpeechKeywordRecognized(SpeechEventData eventData)
952955 if ( Enabled && ShouldListen ( eventData . MixedRealityInputAction ) )
953956 {
954957 StartGlobalVisual ( true ) ;
955-
958+
956959 IncreaseDimensionIndex ( ) ;
957960 SendVoiceCommands ( eventData . RecognizedText , 0 , 1 ) ;
958961
@@ -969,15 +972,15 @@ protected void SetupVoiceCommand()
969972#if UNITY_STANDALONE_WIN || UNITY_WSA || UNITY_EDITOR_WIN
970973 if ( ! string . IsNullOrEmpty ( VoiceCommand ) && VoiceCommand . Length > 2 )
971974 {
972- voiceCommands = new string [ ] { VoiceCommand } ;
975+ voiceCommands = new string [ ] { VoiceCommand } ;
973976 if ( VoiceCommand . IndexOf ( "," ) > - 1 )
974977 {
975978 voiceCommands = VoiceCommand . Split ( ',' ) ;
976979 }
977980
978981 recognitionConfidenceLevel = MixedRealityToolkit . Instance . ActiveProfile . InputSystemProfile . SpeechCommandsProfile . SpeechRecognitionConfidenceLevel ;
979982
980- if ( keywordRecognizer == null )
983+ if ( keywordRecognizer == null )
981984 {
982985 keywordRecognizer = new KeywordRecognizer ( voiceCommands , ( ConfidenceLevel ) recognitionConfidenceLevel ) ;
983986 keywordRecognizer . OnPhraseRecognized += KeywordRecognizer_OnPhraseRecognized ;
@@ -1012,7 +1015,7 @@ protected void KeywordRecognizer_OnPhraseRecognized(PhraseRecognizedEventArgs ar
10121015 {
10131016 if ( args . text == VoiceCommand && ( ! RequiresFocus || HasFocus ) && CanInteract ( ) )
10141017 {
1015-
1018+
10161019 if ( CanInteract ( ) )
10171020 {
10181021 StartGlobalVisual ( true ) ;
@@ -1063,11 +1066,11 @@ protected void SendVoiceCommands(string command, int index, int length)
10631066 /// <returns></returns>
10641067 protected int GetVoiceCommandIndex ( string command )
10651068 {
1066- if ( voiceCommands . Length > 1 )
1069+ if ( voiceCommands . Length > 1 )
10671070 {
10681071 for ( int i = 0 ; i < voiceCommands . Length ; i ++ )
10691072 {
1070- if ( command == voiceCommands [ i ] )
1073+ if ( command == voiceCommands [ i ] )
10711074 {
10721075 return i ;
10731076 }
@@ -1076,7 +1079,7 @@ protected int GetVoiceCommandIndex(string command)
10761079
10771080 return 0 ;
10781081 }
1079-
1082+
10801083 #endregion VoiceCommands
10811084
10821085 }
0 commit comments