55using System . Collections . Generic ;
66using UnityEngine ;
77using UnityEngine . EventSystems ;
8+ using UnityEngine . Windows . Speech ;
89
910namespace HoloToolkit . Unity . InputModule
1011{
@@ -41,6 +42,8 @@ public class InputManager : Singleton<InputManager>
4142 private ManipulationEventData manipulationEventData ;
4243 private HoldEventData holdEventData ;
4344 private NavigationEventData navigationEventData ;
45+ private SpeechKeywordRecognizedEventData speechKeywordRecognizedEventData ;
46+ private DictationEventData dictationEventData ;
4447
4548 /// <summary>
4649 /// Indicates if input is currently enabled or not.
@@ -170,18 +173,6 @@ public void ClearInputDisableStack()
170173 }
171174 }
172175
173- private void Start ( )
174- {
175- InitializeEventDatas ( ) ;
176-
177- if ( GazeManager . Instance == null )
178- {
179- Debug . LogError ( "InputManager requires an active GazeManager in the scene" ) ;
180- }
181-
182- RegisterGazeManager ( ) ;
183- }
184-
185176 private void InitializeEventDatas ( )
186177 {
187178 inputEventData = new InputEventData ( EventSystem . current ) ;
@@ -190,11 +181,22 @@ private void InitializeEventDatas()
190181 manipulationEventData = new ManipulationEventData ( EventSystem . current ) ;
191182 navigationEventData = new NavigationEventData ( EventSystem . current ) ;
192183 holdEventData = new HoldEventData ( EventSystem . current ) ;
184+ speechKeywordRecognizedEventData = new SpeechKeywordRecognizedEventData ( EventSystem . current ) ;
185+ dictationEventData = new DictationEventData ( EventSystem . current ) ;
193186 }
194187
195- protected override void OnDestroy ( )
188+ #region Unity Methods
189+
190+ private void Start ( )
196191 {
197- UnregisterGazeManager ( ) ;
192+ InitializeEventDatas ( ) ;
193+
194+ if ( GazeManager . Instance == null )
195+ {
196+ Debug . LogError ( "InputManager requires an active GazeManager in the scene" ) ;
197+ }
198+
199+ RegisterGazeManager ( ) ;
198200 }
199201
200202 private void OnEnable ( )
@@ -207,10 +209,17 @@ private void OnDisable()
207209 UnregisterGazeManager ( ) ;
208210 }
209211
212+ protected override void OnDestroy ( )
213+ {
214+ UnregisterGazeManager ( ) ;
215+ }
216+
217+ #endregion // Unity Methods
218+
210219 public void HandleEvent < T > ( BaseEventData eventData , ExecuteEvents . EventFunction < T > eventHandler )
211220 where T : IEventSystemHandler
212221 {
213- if ( ! enabled || disabledRefCount > 0 )
222+ if ( ! Instance . enabled || disabledRefCount > 0 )
214223 {
215224 return ;
216225 }
@@ -439,6 +448,8 @@ public void RaiseSourceLost(IInputSource source, uint sourceId)
439448 HandleEvent ( sourceStateEventData , OnSourceLostEventHandler ) ;
440449 }
441450
451+ #region Manipulation Events
452+
442453 private static readonly ExecuteEvents . EventFunction < IManipulationHandler > OnManipulationStartedEventHandler =
443454 delegate ( IManipulationHandler handler , BaseEventData eventData )
444455 {
@@ -503,6 +514,10 @@ public void RaiseManipulationCanceled(IInputSource source, uint sourceId, Vector
503514 HandleEvent ( manipulationEventData , OnManipulationCanceledEventHandler ) ;
504515 }
505516
517+ #endregion // Manipulation Events
518+
519+ #region Hold Events
520+
506521 private static readonly ExecuteEvents . EventFunction < IHoldHandler > OnHoldStartedEventHandler =
507522 delegate ( IHoldHandler handler , BaseEventData eventData )
508523 {
@@ -551,6 +566,10 @@ public void RaiseHoldCanceled(IInputSource source, uint sourceId)
551566 HandleEvent ( holdEventData , OnHoldCanceledEventHandler ) ;
552567 }
553568
569+ #endregion // Hold Events
570+
571+ #region Navigation Events
572+
554573 private static readonly ExecuteEvents . EventFunction < INavigationHandler > OnNavigationStartedEventHandler =
555574 delegate ( INavigationHandler handler , BaseEventData eventData )
556575 {
@@ -615,5 +634,97 @@ public void RaiseNavigationCanceled(IInputSource source, uint sourceId, Vector3
615634 HandleEvent ( navigationEventData , OnNavigationCanceledEventHandler ) ;
616635 }
617636
637+ #endregion // Navigation Events
638+
639+ #region Speech Events
640+
641+
642+ private static readonly ExecuteEvents . EventFunction < ISpeechHandler > OnSpeechKeywordRecognizedEventHandler =
643+ delegate ( ISpeechHandler handler , BaseEventData eventData )
644+ {
645+ SpeechKeywordRecognizedEventData casted = ExecuteEvents . ValidateEventData < SpeechKeywordRecognizedEventData > ( eventData ) ;
646+ handler . OnSpeechKeywordRecognized ( casted ) ;
647+ } ;
648+
649+
650+ public void RaiseSpeechKeywordPhraseRecognized ( IInputSource source , uint sourceId , ConfidenceLevel confidence , TimeSpan phraseDuration , DateTime phraseStartTime , SemanticMeaning [ ] semanticMeanings , string text )
651+ {
652+ // Create input event
653+ speechKeywordRecognizedEventData . Initialize ( source , sourceId , confidence , phraseDuration , phraseStartTime , semanticMeanings , text ) ;
654+
655+ // Pass handler through HandleEvent to perform modal/fallback logic
656+ HandleEvent ( speechKeywordRecognizedEventData , OnSpeechKeywordRecognizedEventHandler ) ;
657+ }
658+
659+ private static readonly ExecuteEvents . EventFunction < IDictationHandler > OnDictationHypothesisEventHandler =
660+ delegate ( IDictationHandler handler , BaseEventData eventData )
661+ {
662+ DictationEventData casted = ExecuteEvents . ValidateEventData < DictationEventData > ( eventData ) ;
663+ handler . OnDictationHypothesis ( casted ) ;
664+ } ;
665+
666+ #endregion // Speech Events
667+
668+ #region Dictation Events
669+
670+ public void RaiseDictationHypothesis ( IInputSource source , uint sourceId , string dictationHypothesis , AudioClip dictationAudioClip = null )
671+ {
672+ // Create input event
673+ dictationEventData . Initialize ( source , sourceId , dictationHypothesis , dictationAudioClip ) ;
674+
675+ // Pass handler through HandleEvent to perform modal/fallback logic
676+ HandleEvent ( dictationEventData , OnDictationHypothesisEventHandler ) ;
677+ }
678+
679+ private static readonly ExecuteEvents . EventFunction < IDictationHandler > OnDictationResultEventHandler =
680+ delegate ( IDictationHandler handler , BaseEventData eventData )
681+ {
682+ DictationEventData casted = ExecuteEvents . ValidateEventData < DictationEventData > ( eventData ) ;
683+ handler . OnDictationResult ( casted ) ;
684+ } ;
685+
686+ public void RaiseDictationResult ( IInputSource source , uint sourceId , string dictationResult , AudioClip dictationAudioClip = null )
687+ {
688+ // Create input event
689+ dictationEventData . Initialize ( source , sourceId , dictationResult , dictationAudioClip ) ;
690+
691+ // Pass handler through HandleEvent to perform modal/fallback logic
692+ HandleEvent ( dictationEventData , OnDictationResultEventHandler ) ;
693+ }
694+
695+ private static readonly ExecuteEvents . EventFunction < IDictationHandler > OnDictationCompleteEventHandler =
696+ delegate ( IDictationHandler handler , BaseEventData eventData )
697+ {
698+ DictationEventData casted = ExecuteEvents . ValidateEventData < DictationEventData > ( eventData ) ;
699+ handler . OnDictationComplete ( casted ) ;
700+ } ;
701+
702+ public void RaiseDictationComplete ( IInputSource source , uint sourceId , string dictationResult , AudioClip dictationAudioClip )
703+ {
704+ // Create input event
705+ dictationEventData . Initialize ( source , sourceId , dictationResult , dictationAudioClip ) ;
706+
707+ // Pass handler through HandleEvent to perform modal/fallback logic
708+ HandleEvent ( dictationEventData , OnDictationCompleteEventHandler ) ;
709+ }
710+
711+ private static readonly ExecuteEvents . EventFunction < IDictationHandler > OnDictationErrorEventHandler =
712+ delegate ( IDictationHandler handler , BaseEventData eventData )
713+ {
714+ DictationEventData casted = ExecuteEvents . ValidateEventData < DictationEventData > ( eventData ) ;
715+ handler . OnDictationComplete ( casted ) ;
716+ } ;
717+
718+ public void RaiseDictationError ( IInputSource source , uint sourceId , string dictationResult , AudioClip dictationAudioClip = null )
719+ {
720+ // Create input event
721+ dictationEventData . Initialize ( source , sourceId , dictationResult , dictationAudioClip ) ;
722+
723+ // Pass handler through HandleEvent to perform modal/fallback logic
724+ HandleEvent ( dictationEventData , OnDictationErrorEventHandler ) ;
725+ }
726+
727+ #endregion // Dictation Events
728+
618729 }
619730}
0 commit comments