| | | 1 | | using UnityEngine; |
| | | 2 | | using UnityEngine.XR.Interaction.Toolkit; |
| | | 3 | | |
| | | 4 | | /// <summary> |
| | | 5 | | /// Manually teleport the player to a specific anchor |
| | | 6 | | /// </summary> |
| | | 7 | | public class TeleportPlayer : MonoBehaviour |
| | | 8 | | { |
| | | 9 | | [Tooltip("The anchor the player is teleported to")] |
| | 4 | 10 | | public TeleportationAnchor anchor = null; |
| | | 11 | | |
| | | 12 | | [Tooltip("The provider used to request the teleportation")] |
| | 4 | 13 | | public TeleportationProvider provider = null; |
| | | 14 | | |
| | | 15 | | public void Teleport() |
| | 2 | 16 | | { |
| | 2 | 17 | | if(anchor && provider) |
| | 2 | 18 | | { |
| | 2 | 19 | | TeleportRequest request = CreateRequest(); |
| | 2 | 20 | | provider.QueueTeleportRequest(request); |
| | 2 | 21 | | } |
| | 2 | 22 | | } |
| | | 23 | | |
| | | 24 | | private TeleportRequest CreateRequest() |
| | 2 | 25 | | { |
| | 2 | 26 | | Transform anchorTransform = anchor.teleportAnchorTransform; |
| | | 27 | | |
| | 2 | 28 | | TeleportRequest request = new TeleportRequest() |
| | | 29 | | { |
| | | 30 | | requestTime = Time.time, |
| | | 31 | | matchOrientation = anchor.matchOrientation, |
| | | 32 | | |
| | | 33 | | destinationPosition = anchorTransform.position, |
| | | 34 | | destinationRotation = anchorTransform.rotation |
| | | 35 | | }; |
| | | 36 | | |
| | 2 | 37 | | return request; |
| | 2 | 38 | | } |
| | | 39 | | } |