@@ -11,7 +11,8 @@ namespace HoloToolkit.Unity.InputModule
1111 /// <summary>
1212 /// Script teleports the user to the location being gazed at when Y was pressed on a Gamepad.
1313 /// </summary>
14- public class MixedRealityTeleport : Singleton < MixedRealityTeleport >
14+ [ RequireComponent ( typeof ( SetGlobalListener ) ) ]
15+ public class MixedRealityTeleport : Singleton < MixedRealityTeleport > , IControllerInputHandler
1516 {
1617 [ Tooltip ( "Name of the joystick axis to move along X." ) ]
1718 public string LeftJoystickX = "ControllerLeftStickX" ;
@@ -23,10 +24,6 @@ public class MixedRealityTeleport : Singleton<MixedRealityTeleport>
2324 public bool EnableRotation = true ;
2425 public bool EnableStrafe = true ;
2526
26- public bool EnableJoystickMovement = false ;
27-
28- public float SpeedScale { get ; set ; }
29-
3027 public float RotationSize = 45.0f ;
3128 public float StrafeAmount = 0.5f ;
3229
@@ -39,11 +36,10 @@ public class MixedRealityTeleport : Singleton<MixedRealityTeleport>
3936 /// </summary>
4037 private FadeScript fadeControl ;
4138
42- private GazeManager gazeManager ;
43- private Vector3 positionBeforeJump = Vector3 . zero ;
4439 private GameObject teleportMarker ;
45- private bool teleportValid ;
46- private bool teleporting ;
40+ private bool isTeleportValid ;
41+ private IPointingSource currentPointingSource ;
42+ private uint currentSourceId ;
4743
4844 private void Start ( )
4945 {
@@ -53,11 +49,7 @@ private void Start()
5349 return ;
5450 }
5551
56- InteractionManager . InteractionSourceUpdated += InteractionManager_InteractionSourceUpdated ;
57-
58- gazeManager = GazeManager . Instance ;
5952 fadeControl = FadeScript . Instance ;
60- SpeedScale = 0.6f ;
6153
6254 teleportMarker = Instantiate ( TeleportMarker ) ;
6355 teleportMarker . SetActive ( false ) ;
@@ -76,7 +68,7 @@ void Update()
7668 HandleGamepad ( ) ;
7769 }
7870
79- if ( teleporting )
71+ if ( currentPointingSource != null )
8072 {
8173 PositionMarker ( ) ;
8274 }
@@ -89,17 +81,20 @@ private void HandleGamepad()
8981 float leftX = Input . GetAxis ( "ControllerLeftStickX" ) ;
9082 float leftY = Input . GetAxis ( "ControllerLeftStickY" ) ;
9183
92- if ( ! teleporting && leftY > 0.8 && Math . Abs ( leftX ) < 0.2 )
84+ if ( currentPointingSource == null && leftY > 0.8 && Math . Abs ( leftX ) < 0.2 )
9385 {
94- StartTeleport ( ) ;
86+ if ( FocusManager . Instance . TryGetSinglePointer ( out currentPointingSource ) )
87+ {
88+ StartTeleport ( ) ;
89+ }
9590 }
96- else if ( teleporting && Math . Sqrt ( Math . Pow ( leftX , 2 ) + Math . Pow ( leftY , 2 ) ) < 0.1 )
91+ else if ( currentPointingSource != null && Math . Sqrt ( Math . Pow ( leftX , 2 ) + Math . Pow ( leftY , 2 ) ) < 0.1 )
9792 {
9893 FinishTeleport ( ) ;
9994 }
10095 }
10196
102- if ( EnableStrafe && ! teleporting && ! fadeControl . Busy )
97+ if ( EnableStrafe && currentPointingSource == null && ! fadeControl . Busy )
10398 {
10499 float leftX = Input . GetAxis ( "ControllerLeftStickX" ) ;
105100 float leftY = Input . GetAxis ( "ControllerLeftStickY" ) ;
@@ -118,7 +113,7 @@ private void HandleGamepad()
118113 }
119114 }
120115
121- if ( EnableRotation && ! teleporting && ! fadeControl . Busy )
116+ if ( EnableRotation && currentPointingSource == null && ! fadeControl . Busy )
122117 {
123118 float rightX = Input . GetAxis ( "ControllerRightStickX" ) ;
124119 float rightY = Input . GetAxis ( "ControllerRightStickY" ) ;
@@ -133,36 +128,40 @@ private void HandleGamepad()
133128 }
134129 }
135130 }
136-
137- private void InteractionManager_InteractionSourceUpdated ( InteractionSourceUpdatedEventArgs obj )
131+
132+ void IControllerInputHandler . OnInputPositionChanged ( InputPositionEventData eventData )
138133 {
139134 if ( EnableTeleport )
140135 {
141- if ( ! teleporting && obj . state . thumbstickPosition . y > 0.8 && Math . Abs ( obj . state . thumbstickPosition . x ) < 0.2 )
136+ if ( currentPointingSource == null && eventData . Position . y > 0.8 && Math . Abs ( eventData . Position . x ) < 0.2 )
142137 {
143- StartTeleport ( ) ;
138+ if ( FocusManager . Instance . TryGetPointingSource ( eventData , out currentPointingSource ) )
139+ {
140+ currentSourceId = eventData . SourceId ;
141+ StartTeleport ( ) ;
142+ }
144143 }
145- else if ( teleporting && obj . state . thumbstickPosition . magnitude < 0.1 )
144+ else if ( currentPointingSource != null && currentSourceId == eventData . SourceId && eventData . Position . magnitude < 0.1 )
146145 {
147146 FinishTeleport ( ) ;
148147 }
149148 }
150149
151- if ( EnableStrafe && ! teleporting && ! fadeControl . Busy )
150+ if ( EnableStrafe && currentPointingSource == null )
152151 {
153- if ( obj . state . thumbstickPosition . y < - 0.8 && Math . Abs ( obj . state . thumbstickPosition . x ) < 0.2 )
152+ if ( eventData . Position . y < - 0.8 && Math . Abs ( eventData . Position . x ) < 0.2 )
154153 {
155154 DoStrafe ( Vector3 . back * StrafeAmount ) ;
156155 }
157156 }
158157
159- if ( EnableRotation && ! teleporting && ! fadeControl . Busy )
158+ if ( EnableRotation && currentPointingSource == null )
160159 {
161- if ( obj . state . thumbstickPosition . x < - 0.8 && Math . Abs ( obj . state . thumbstickPosition . y ) < 0.2 )
160+ if ( eventData . Position . x < - 0.8 && Math . Abs ( eventData . Position . y ) < 0.2 )
162161 {
163162 DoRotation ( - RotationSize ) ;
164163 }
165- else if ( obj . state . thumbstickPosition . x > 0.8 && Math . Abs ( obj . state . thumbstickPosition . y ) < 0.2 )
164+ else if ( eventData . Position . x > 0.8 && Math . Abs ( eventData . Position . y ) < 0.2 )
166165 {
167166 DoRotation ( RotationSize ) ;
168167 }
@@ -171,21 +170,20 @@ private void InteractionManager_InteractionSourceUpdated(InteractionSourceUpdate
171170
172171 public void StartTeleport ( )
173172 {
174- if ( ! teleporting && ! fadeControl . Busy )
173+ if ( currentPointingSource != null && ! fadeControl . Busy )
175174 {
176- teleporting = true ;
177175 EnableMarker ( ) ;
178176 PositionMarker ( ) ;
179177 }
180178 }
181179
182180 private void FinishTeleport ( )
183181 {
184- if ( teleporting )
182+ if ( currentPointingSource != null )
185183 {
186- teleporting = false ;
184+ currentPointingSource = null ;
187185
188- if ( teleportValid )
186+ if ( isTeleportValid )
189187 {
190188 RaycastHit hitInfo ;
191189 Vector3 hitPos = teleportMarker . transform . position + Vector3 . up * ( Physics . Raycast ( Camera . main . transform . position , Vector3 . down , out hitInfo , 5.0f ) ? hitInfo . distance : 2.6f ) ;
@@ -263,41 +261,20 @@ private void DisableMarker()
263261
264262 private void PositionMarker ( )
265263 {
266- Vector3 hitNormal = HitNormal ( ) ;
267- if ( Vector3 . Dot ( hitNormal , Vector3 . up ) > 0.90f )
264+ FocusDetails focusDetails = FocusManager . Instance . GetFocusDetails ( currentPointingSource ) ;
265+
266+ if ( focusDetails . Object != null && ( Vector3 . Dot ( focusDetails . Normal , Vector3 . up ) > 0.90f ) )
268267 {
269- teleportValid = true ;
268+ isTeleportValid = true ;
270269
271- IPointingSource pointingSource ;
272- if ( FocusManager . Instance . TryGetSinglePointer ( out pointingSource ) )
273- {
274- teleportMarker . transform . position = FocusManager . Instance . GetFocusDetails ( pointingSource ) . Point ;
275- }
270+ teleportMarker . transform . position = focusDetails . Point ;
276271 }
277272 else
278273 {
279- teleportValid = false ;
280- }
281-
282- animationController . speed = teleportValid ? 1 : 0 ;
283- }
284-
285- private Vector3 HitNormal ( )
286- {
287- Vector3 retval = Vector3 . zero ;
288-
289- IPointingSource pointingSource ;
290- if ( FocusManager . Instance . TryGetSinglePointer ( out pointingSource ) )
291- {
292- FocusDetails focusDetails = FocusManager . Instance . GetFocusDetails ( pointingSource ) ;
293-
294- if ( focusDetails . Object != null )
295- {
296- retval = focusDetails . Normal ;
297- }
274+ isTeleportValid = false ;
298275 }
299276
300- return retval ;
277+ animationController . speed = isTeleportValid ? 1 : 0 ;
301278 }
302279 }
303280}
0 commit comments