1- using UnityEngine ;
1+ using System ;
2+ using UnityEngine ;
23using UnityEngine . XR . WSA . Input ;
34
45namespace HoloToolkit . Unity . InputModule
56{
67 /// <summary>
78 /// Script teleports the user to the location being gazed at when Y was pressed on a Gamepad.
89 /// </summary>
9- public class MixedRealityTeleport : Singleton < MixedRealityTeleport >
10+ public class MixedRealityTeleport : Singleton < MixedRealityTeleport > , IControllerInputHandler
1011 {
11- [ Tooltip ( "Game pad button to press for teleporting or jump." ) ]
12- public string TeleportButtonName = "Jump" ;
13-
14- [ Tooltip ( "Game pad button to press for going back to a state." ) ]
15- public string GoBackButtonName = "Fire2" ;
16-
1712 [ Tooltip ( "Name of the joystick axis to move along X." ) ]
1813 public string LeftJoystickX = "ControllerLeftStickX" ;
1914
@@ -26,7 +21,7 @@ public class MixedRealityTeleport : Singleton<MixedRealityTeleport>
2621
2722 public float SpeedScale { get ; set ; }
2823
29- public float BumperRotationSize = 30 .0f;
24+ public float BumperRotationSize = 45 .0f;
3025
3126 public GameObject TeleportMarker ;
3227 private Animator animationController ;
@@ -61,79 +56,13 @@ private void Start()
6156
6257 void Update ( )
6358 {
64- HandleTeleport ( ) ;
65- HandleGoBackPressed ( ) ;
6659 HandleJoystickMovement ( ) ;
6760 if ( InteractionManager . numSourceStates == 0 )
6861 {
6962 HandleBumperRotation ( ) ;
7063 }
7164 }
7265
73- private void HandleTeleport ( )
74- {
75- if ( EnableTeleport )
76- {
77- if ( teleporting )
78- {
79- if ( Input . GetButtonUp ( TeleportButtonName ) )
80- {
81- teleporting = false ;
82- if ( teleportValid )
83- {
84- positionBeforeJump = transform . position ;
85- float verticalOffset ;
86- RaycastHit hitInfo ;
87- if ( Physics . Raycast ( Camera . main . transform . position , Vector3 . down , out hitInfo , 5.0f ) )
88- {
89- verticalOffset = hitInfo . distance ;
90- }
91- else
92- {
93- verticalOffset = 2.6f ;
94- }
95-
96- Vector3 hitPos = teleportMarker . transform . position + Vector3 . up * verticalOffset ;
97-
98- fadeControl . DoFade ( 0.25f , 0.5f , ( ) =>
99- {
100- SetWorldPosition ( hitPos ) ;
101- } , null ) ;
102- }
103-
104- DisableMarker ( ) ;
105- }
106- else
107- {
108- PositionMarker ( ) ;
109- }
110- }
111- else
112- {
113- if ( fadeControl . Busy == false && Input . GetButtonDown ( TeleportButtonName ) )
114- {
115- teleporting = true ;
116- EnableMarker ( ) ;
117- PositionMarker ( ) ;
118- }
119- }
120- }
121- }
122-
123- private void HandleGoBackPressed ( )
124- {
125- if ( EnableTeleport && Input . GetButtonDown ( GoBackButtonName ) )
126- {
127- Vector3 oldPositionBeforeJump = positionBeforeJump ;
128- positionBeforeJump = transform . position ;
129-
130- fadeControl . DoFade ( 0.25f , 0.5f , ( ) =>
131- {
132- SetWorldPosition ( oldPositionBeforeJump ) ;
133- } , null ) ;
134- }
135- }
136-
13766 private void HandleJoystickMovement ( )
13867 {
13968 if ( EnableJoystickMovement )
@@ -221,7 +150,12 @@ private void PositionMarker()
221150 if ( Vector3 . Dot ( hitNormal , Vector3 . up ) > 0.90f )
222151 {
223152 teleportValid = true ;
224- teleportMarker . transform . position = gazeManager . HitPosition ;
153+
154+ IPointingSource pointingSource ;
155+ if ( FocusManager . Instance . TryGetSinglePointer ( out pointingSource ) )
156+ {
157+ teleportMarker . transform . position = FocusManager . Instance . GetFocusDetails ( pointingSource ) . Point ;
158+ }
225159 }
226160 else
227161 {
@@ -234,11 +168,70 @@ private void PositionMarker()
234168 private Vector3 HitNormal ( )
235169 {
236170 Vector3 retval = Vector3 . zero ;
237- if ( gazeManager . HitObject != null )
171+
172+ IPointingSource pointingSource ;
173+ if ( FocusManager . Instance . TryGetSinglePointer ( out pointingSource ) )
238174 {
239- retval = gazeManager . HitNormal ;
175+ FocusDetails focusDetails = FocusManager . Instance . GetFocusDetails ( pointingSource ) ;
176+
177+ if ( focusDetails . Object != null )
178+ {
179+ retval = focusDetails . Normal ;
180+ }
240181 }
182+
241183 return retval ;
242184 }
185+
186+ void IControllerInputHandler . OnSelectPressedAmountChanged ( SelectPressedEventData eventData )
187+ {
188+ }
189+
190+ void IControllerInputHandler . OnInputPositionChanged ( InputPositionEventData eventData )
191+ {
192+ if ( EnableTeleport )
193+ {
194+ if ( fadeControl . Busy == false && teleporting == false && eventData . PressType == InteractionSourcePressType . Thumbstick && Math . Abs ( 1.0 - eventData . Position . y ) < 0.2 && Math . Abs ( eventData . Position . x ) < 0.1 )
195+ {
196+ teleporting = true ;
197+ EnableMarker ( ) ;
198+ PositionMarker ( ) ;
199+ }
200+ else if ( teleporting )
201+ {
202+ if ( eventData . PressType == InteractionSourcePressType . Thumbstick && eventData . Position . magnitude < 0.1 )
203+ {
204+ teleporting = false ;
205+ if ( teleportValid )
206+ {
207+ positionBeforeJump = transform . position ;
208+ float verticalOffset ;
209+ RaycastHit hitInfo ;
210+ if ( Physics . Raycast ( Camera . main . transform . position , Vector3 . down , out hitInfo , 5.0f ) )
211+ {
212+ verticalOffset = hitInfo . distance ;
213+ }
214+ else
215+ {
216+ verticalOffset = 2.6f ;
217+ }
218+
219+ Vector3 hitPos = teleportMarker . transform . position + Vector3 . up * verticalOffset ;
220+
221+ fadeControl . DoFade ( 0.25f , 0.5f , ( ) =>
222+ {
223+ SetWorldPosition ( hitPos ) ;
224+ } , null ) ;
225+ }
226+
227+ DisableMarker ( ) ;
228+ }
229+ else
230+ {
231+ PositionMarker ( ) ;
232+ }
233+ }
234+ }
235+ }
243236 }
244237}
0 commit comments