7 #if UNITY_2017_2_OR_NEWER 25 [RequireComponent(typeof(SetGlobalListener))]
28 [Tooltip(
"Name of the thumbstick axis to check for teleport and strafe.")]
31 [Tooltip(
"Name of the thumbstick axis to check for movement forwards and backwards.")]
34 [Tooltip(
"Name of the thumbstick axis to check for rotation.")]
37 [Tooltip(
"Name of the thumbstick axis to check for rotation.")]
40 [Tooltip(
"Custom Input Mapping for horizontal teleport and strafe")]
43 [Tooltip(
"Name of the thumbstick axis to check for movement forwards and backwards.")]
46 [Tooltip(
"Custom Input Mapping for horizontal rotation")]
49 [Tooltip(
"Custom Input Mapping for vertical rotation")]
52 public bool EnableTeleport =
true;
53 public bool EnableRotation =
true;
54 public bool EnableStrafe =
true;
56 [Tooltip(
"Makes sure you don't get put 'on top' of holograms, just on the floor. If true, your height won't change as a result of a teleport.")]
57 public bool StayOnTheFloor =
false;
59 public float RotationSize = 45.0f;
60 public float StrafeAmount = 0.5f;
63 private GameObject teleportMarker;
64 private Animator animationController;
67 private bool useCustomMapping =
false;
75 private bool isTeleportValid;
77 private uint currentSourceId;
83 #if UNITY_2017_2_OR_NEWER 84 if (!XRDevice.isPresent
86 || !HolographicSettings.IsDisplayOpaque
90 if (VRDevice.isPresent)
105 if (fadeControl == null)
111 if (teleportMarker != null)
113 teleportMarker = Instantiate(teleportMarker);
114 teleportMarker.SetActive(
false);
116 animationController = teleportMarker.GetComponentInChildren<Animator>();
117 if (animationController != null)
119 animationController.StopPlayback();
124 private void Update()
127 if (InteractionManager.numSourceStates == 0)
133 if (currentPointingSource != null)
139 private void HandleGamepad()
141 if (EnableTeleport && !fadeControl.
Busy)
146 if (currentPointingSource == null && leftY > 0.8 && Math.Abs(leftX) < 0.3)
153 else if (currentPointingSource != null &&
new Vector2(leftX, leftY).magnitude < 0.2)
159 if (EnableStrafe && currentPointingSource == null && !fadeControl.
Busy)
164 if (leftX < -0.8 && Math.Abs(leftY) < 0.3)
166 DoStrafe(Vector3.left * StrafeAmount);
168 else if (leftX > 0.8 && Math.Abs(leftY) < 0.3)
170 DoStrafe(Vector3.right * StrafeAmount);
172 else if (leftY < -0.8 && Math.Abs(leftX) < 0.3)
174 DoStrafe(Vector3.back * StrafeAmount);
178 if (EnableRotation && currentPointingSource == null && !fadeControl.
Busy)
183 if (rightX < -0.8 && Math.Abs(rightY) < 0.3)
185 DoRotation(-RotationSize);
187 else if (rightX > 0.8 && Math.Abs(rightY) < 0.3)
189 DoRotation(RotationSize);
200 if (currentPointingSource == null && eventData.
Position.y > 0.8 && Math.Abs(eventData.
Position.x) < 0.3)
204 currentSourceId = eventData.
SourceId;
208 else if (currentPointingSource != null && currentSourceId == eventData.
SourceId && eventData.
Position.magnitude < 0.2)
214 if (EnableStrafe && currentPointingSource == null)
218 DoStrafe(Vector3.back * StrafeAmount);
222 if (EnableRotation && currentPointingSource == null)
226 DoRotation(-RotationSize);
228 else if (eventData.
Position.x > 0.8 && Math.Abs(eventData.
Position.y) < 0.3)
230 DoRotation(RotationSize);
238 if (currentPointingSource != null && !fadeControl.
Busy)
245 private void FinishTeleport()
247 if (currentPointingSource != null)
249 currentPointingSource = null;
253 fadeControl.
DoFade(0.25f, 0.5f, () =>
255 SetWorldPosition(teleportMarker.transform.position);
265 if (rotationAmount != 0 && !fadeControl.
Busy)
272 transform.RotateAround(
CameraCache.
Main.transform.position, Vector3.up, rotationAmount);
279 if (strafeAmount.magnitude != 0 && !fadeControl.
Busy)
287 transformToRotate.rotation = Quaternion.Euler(0, transformToRotate.rotation.eulerAngles.y, 0);
303 var newPosition = worldPosition - (
CameraCache.
Main.transform.position - transform.position);
306 #if UNITY_2017_2_OR_NEWER 307 if (XRDevice.GetTrackingSpaceType() == TrackingSpaceType.Stationary && !StayOnTheFloor)
309 if (VRDevice.GetTrackingSpaceType() == TrackingSpaceType.Stationary && !StayOnTheFloor)
313 newPosition.y += (Physics.Raycast(
CameraCache.
Main.transform.position, Vector3.down, out hitInfo, 5.0f) ? hitInfo.distance : 1.7f);
317 newPosition.y = StayOnTheFloor ? transform.position.y : worldPosition.y;
320 transform.position = newPosition;
323 private void EnableMarker()
325 teleportMarker.SetActive(
true);
326 if (animationController != null)
328 animationController.StartPlayback();
332 private void DisableMarker()
334 if (animationController != null)
336 animationController.StopPlayback();
338 teleportMarker.SetActive(
false);
341 private void PositionMarker()
345 if (focusDetails.
Object != null && (Vector3.Dot(focusDetails.
Normal, Vector3.up) > 0.90f))
347 isTeleportValid =
true;
349 teleportMarker.transform.position = focusDetails.
Point;
353 isTeleportValid =
false;
356 animationController.speed = isTeleportValid ? 1 : 0;