11// Copyright (c) Microsoft Corporation. All rights reserved.
22// Licensed under the MIT License. See LICENSE in the project root for license information.
33
4- using Microsoft . MixedReality . Toolkit . InputSystem . Sources ;
54using Microsoft . MixedReality . Toolkit . Core . Definitions . Devices ;
65using Microsoft . MixedReality . Toolkit . Core . Definitions . InputSystem ;
76using Microsoft . MixedReality . Toolkit . Core . Definitions . Utilities ;
1211using Microsoft . MixedReality . Toolkit . Core . Interfaces . InputSystem . Handlers ;
1312using Microsoft . MixedReality . Toolkit . Core . Managers ;
1413using Microsoft . MixedReality . Toolkit . Core . Utilities ;
14+ using Microsoft . MixedReality . Toolkit . InputSystem . Sources ;
1515using System ;
1616using System . Collections . Generic ;
1717using UnityEngine ;
@@ -50,7 +50,11 @@ public class MixedRealityInputManager : MixedRealityEventManager, IMixedRealityI
5050 private int disabledRefCount ;
5151
5252 private SourceStateEventData sourceStateEventData ;
53- private SourcePoseEventData sourcePoseEventData ;
53+ private SourcePoseEventData < TrackingState > sourceTrackingEventData ;
54+ private SourcePoseEventData < Vector2 > sourceVector2EventData ;
55+ private SourcePoseEventData < Vector3 > sourcePositionEventData ;
56+ private SourcePoseEventData < Quaternion > sourceRotationEventData ;
57+ private SourcePoseEventData < MixedRealityPose > sourcePoseEventData ;
5458
5559 private FocusEventData focusEventData ;
5660
@@ -63,13 +67,9 @@ public class MixedRealityInputManager : MixedRealityEventManager, IMixedRealityI
6367 private InputEventData < Quaternion > rotationInputEventData ;
6468 private InputEventData < MixedRealityPose > poseInputEventData ;
6569
66- #if UNITY_STANDALONE_WIN || UNITY_WSA || UNITY_EDITOR_WIN
67-
6870 private SpeechEventData speechEventData ;
6971 private DictationEventData dictationEventData ;
7072
71- #endif // UNITY_STANDALONE_WIN || UNITY_WSA || UNITY_EDITOR_WIN
72-
7373 /// <summary>
7474 /// Current Speech Input Source.
7575 /// </summary>
@@ -184,7 +184,12 @@ private void InitializeInternal()
184184 }
185185
186186 sourceStateEventData = new SourceStateEventData ( EventSystem . current ) ;
187- sourcePoseEventData = new SourcePoseEventData ( EventSystem . current ) ;
187+
188+ sourceTrackingEventData = new SourcePoseEventData < TrackingState > ( EventSystem . current ) ;
189+ sourceVector2EventData = new SourcePoseEventData < Vector2 > ( EventSystem . current ) ;
190+ sourcePositionEventData = new SourcePoseEventData < Vector3 > ( EventSystem . current ) ;
191+ sourceRotationEventData = new SourcePoseEventData < Quaternion > ( EventSystem . current ) ;
192+ sourcePoseEventData = new SourcePoseEventData < MixedRealityPose > ( EventSystem . current ) ;
188193
189194 focusEventData = new FocusEventData ( EventSystem . current ) ;
190195
@@ -197,13 +202,9 @@ private void InitializeInternal()
197202 rotationInputEventData = new InputEventData < Quaternion > ( EventSystem . current ) ;
198203 poseInputEventData = new InputEventData < MixedRealityPose > ( EventSystem . current ) ;
199204
200- #if UNITY_STANDALONE_WIN || UNITY_WSA || UNITY_EDITOR_WIN
201-
202205 speechEventData = new SpeechEventData ( EventSystem . current ) ;
203206 dictationEventData = new DictationEventData ( EventSystem . current ) ;
204207
205- #endif // UNITY_STANDALONE_WIN || UNITY_WSA || UNITY_EDITOR_WIN
206-
207208 if ( MixedRealityManager . Instance . ActiveProfile . IsSpeechCommandsEnabled )
208209 {
209210 SpeechInputSource = new SpeechInputSource (
@@ -578,42 +579,70 @@ public void RaiseSourceLost(IMixedRealityInputSource source, IMixedRealityContro
578579 public void RaiseSourceTrackingStateChanged ( IMixedRealityInputSource source , IMixedRealityController controller , TrackingState state )
579580 {
580581 // Create input event
581- sourcePoseEventData . Initialize ( source , controller , state ) ;
582+ sourceTrackingEventData . Initialize ( source , controller , state ) ;
582583
583584 // Pass handler through HandleEvent to perform modal/fallback logic
584- HandleEvent ( sourcePoseEventData , OnSourcePoseChangedEventHandler ) ;
585+ HandleEvent ( sourceTrackingEventData , OnSourceTrackingChangedEventHandler ) ;
585586 }
586587
588+ private static readonly ExecuteEvents . EventFunction < IMixedRealitySourcePoseHandler > OnSourceTrackingChangedEventHandler =
589+ delegate ( IMixedRealitySourcePoseHandler handler , BaseEventData eventData )
590+ {
591+ var casted = ExecuteEvents . ValidateEventData < SourcePoseEventData < TrackingState > > ( eventData ) ;
592+ handler . OnSourcePoseChanged ( casted ) ;
593+ } ;
594+
587595 /// <inheritdoc />
588596 public void RaiseSourcePositionChanged ( IMixedRealityInputSource source , IMixedRealityController controller , Vector2 position )
589597 {
590598 // Create input event
591- sourcePoseEventData . Initialize ( source , controller , position ) ;
599+ sourceVector2EventData . Initialize ( source , controller , position ) ;
592600
593601 // Pass handler through HandleEvent to perform modal/fallback logic
594- HandleEvent ( sourcePoseEventData , OnSourcePoseChangedEventHandler ) ;
602+ HandleEvent ( sourceVector2EventData , OnSourcePoseVector2ChangedEventHandler ) ;
595603 }
596604
605+ private static readonly ExecuteEvents . EventFunction < IMixedRealitySourcePoseHandler > OnSourcePoseVector2ChangedEventHandler =
606+ delegate ( IMixedRealitySourcePoseHandler handler , BaseEventData eventData )
607+ {
608+ var casted = ExecuteEvents . ValidateEventData < SourcePoseEventData < Vector2 > > ( eventData ) ;
609+ handler . OnSourcePoseChanged ( casted ) ;
610+ } ;
611+
597612 /// <inheritdoc />
598613 public void RaiseSourcePositionChanged ( IMixedRealityInputSource source , IMixedRealityController controller , Vector3 position )
599614 {
600615 // Create input event
601- sourcePoseEventData . Initialize ( source , controller , position ) ;
616+ sourcePositionEventData . Initialize ( source , controller , position ) ;
602617
603618 // Pass handler through HandleEvent to perform modal/fallback logic
604- HandleEvent ( sourcePoseEventData , OnSourcePoseChangedEventHandler ) ;
619+ HandleEvent ( sourcePositionEventData , OnSourcePositionChangedEventHandler ) ;
605620 }
606621
622+ private static readonly ExecuteEvents . EventFunction < IMixedRealitySourcePoseHandler > OnSourcePositionChangedEventHandler =
623+ delegate ( IMixedRealitySourcePoseHandler handler , BaseEventData eventData )
624+ {
625+ var casted = ExecuteEvents . ValidateEventData < SourcePoseEventData < Vector3 > > ( eventData ) ;
626+ handler . OnSourcePoseChanged ( casted ) ;
627+ } ;
628+
607629 /// <inheritdoc />
608630 public void RaiseSourceRotationChanged ( IMixedRealityInputSource source , IMixedRealityController controller , Quaternion rotation )
609631 {
610632 // Create input event
611- sourcePoseEventData . Initialize ( source , controller , rotation ) ;
633+ sourceRotationEventData . Initialize ( source , controller , rotation ) ;
612634
613635 // Pass handler through HandleEvent to perform modal/fallback logic
614- HandleEvent ( sourcePoseEventData , OnSourcePoseChangedEventHandler ) ;
636+ HandleEvent ( sourceRotationEventData , OnSourceRotationChangedEventHandler ) ;
615637 }
616638
639+ private static readonly ExecuteEvents . EventFunction < IMixedRealitySourcePoseHandler > OnSourceRotationChangedEventHandler =
640+ delegate ( IMixedRealitySourcePoseHandler handler , BaseEventData eventData )
641+ {
642+ var casted = ExecuteEvents . ValidateEventData < SourcePoseEventData < Quaternion > > ( eventData ) ;
643+ handler . OnSourcePoseChanged ( casted ) ;
644+ } ;
645+
617646 /// <inheritdoc />
618647 public void RaiseSourcePoseChanged ( IMixedRealityInputSource source , IMixedRealityController controller , MixedRealityPose position )
619648 {
@@ -627,7 +656,7 @@ public void RaiseSourcePoseChanged(IMixedRealityInputSource source, IMixedRealit
627656 private static readonly ExecuteEvents . EventFunction < IMixedRealitySourcePoseHandler > OnSourcePoseChangedEventHandler =
628657 delegate ( IMixedRealitySourcePoseHandler handler , BaseEventData eventData )
629658 {
630- var casted = ExecuteEvents . ValidateEventData < SourcePoseEventData > ( eventData ) ;
659+ var casted = ExecuteEvents . ValidateEventData < SourcePoseEventData < MixedRealityPose > > ( eventData ) ;
631660 handler . OnSourcePoseChanged ( casted ) ;
632661 } ;
633662
@@ -1449,8 +1478,6 @@ public void RaiseManipulationCanceled(IMixedRealityInputSource source, Handednes
14491478
14501479 #endregion Gestures
14511480
1452- #if UNITY_STANDALONE_WIN || UNITY_WSA || UNITY_EDITOR_WIN
1453-
14541481 #region Speech Keyword Events
14551482
14561483 private static readonly ExecuteEvents . EventFunction < IMixedRealitySpeechHandler > OnSpeechKeywordRecognizedEventHandler =
@@ -1544,8 +1571,6 @@ public void RaiseDictationError(IMixedRealityInputSource source, string dictatio
15441571
15451572 #endregion Dictation Events
15461573
1547- #endif // UNITY_STANDALONE_WIN || UNITY_WSA || UNITY_EDITOR_WIN
1548-
15491574 #endregion Input Events
15501575 }
15511576}
0 commit comments