protected override void Awake() { base.Awake(); typeName = "Teleport Arrow"; if (teleportationProvider == null) { teleportationProvider = FindObjectOfType <TeleportationProvider>(); } }
// Start is called before the first frame update void Start() { GameObject player = GameObject.Find("Player"); SmoothTurn = player.GetComponent <DeviceBasedContinuousTurnProvider>(); SnapTurn = player.GetComponent <DeviceBasedSnapTurnProvider>(); continuousMove = player.GetComponent <DeviceBasedContinuousMoveProvider>(); teleport = player.GetComponent <TeleportationProvider>(); }
public IEnumerator TeleportToAnchorWithStraightLineAndMatchTargetUp() { var manager = TestUtilities.CreateInteractionManager(); var xrRig = TestUtilities.CreateXRRig(); // config teleportation on XR rig LocomotionSystem locoSys = xrRig.gameObject.AddComponent <LocomotionSystem>(); TeleportationProvider teleProvider = xrRig.gameObject.AddComponent <TeleportationProvider>(); teleProvider.system = locoSys; // interactor var interactor = TestUtilities.CreateRayInteractor(); interactor.transform.SetParent(xrRig.cameraFloorOffsetObject.transform); interactor.lineType = XRRayInteractor.LineType.StraightLine; // controller var controller = interactor.GetComponent <XRController>(); // create teleportation anchors var teleAnchor = TestUtilities.CreateTeleportAnchorPlane(); teleAnchor.interactionManager = manager; teleAnchor.teleportationProvider = teleProvider; teleAnchor.matchOrientation = MatchOrientation.TargetUp; // set teleportation anchor plane in the forward direction of controller teleAnchor.transform.position = interactor.transform.forward + Vector3.down; teleAnchor.transform.Rotate(-45, 0, 0, Space.World); var controllerRecorder = TestUtilities.CreateControllerRecorder(controller, (recording) => { recording.AddRecordingFrame(0.0f, Vector3.zero, Quaternion.identity, true, false, false); recording.AddRecordingFrame(0.1f, Vector3.zero, Quaternion.identity, true, false, false); recording.AddRecordingFrame(float.MaxValue, Vector3.zero, Quaternion.identity, false, false, false); }); controllerRecorder.isPlaying = true; // wait for 1s to make sure the recorder simulates the action yield return(new WaitForSeconds(1f)); Vector3 cameraPosAdjustment = xrRig.rig.transform.up * xrRig.cameraInRigSpaceHeight; Assert.That(xrRig.cameraGameObject.transform.position, Is.EqualTo(teleAnchor.transform.position + cameraPosAdjustment).Using(Vector3ComparerWithEqualsOperator.Instance)); Assert.That(xrRig.rig.transform.up, Is.EqualTo(teleAnchor.transform.up).Using(Vector3ComparerWithEqualsOperator.Instance)); Vector3 projectedCameraForward = Vector3.ProjectOnPlane(xrRig.cameraGameObject.transform.forward, teleAnchor.transform.up); Assert.That(projectedCameraForward.normalized, Is.EqualTo(teleAnchor.transform.forward).Using(Vector3ComparerWithEqualsOperator.Instance)); }
public IEnumerator TeleportToAnchorWithBezierCurve() { var manager = TestUtilities.CreateInteractionManager(); var xrRig = TestUtilities.CreateXRRig(); // config teleportation on XR rig LocomotionSystem locoSys = xrRig.gameObject.AddComponent <LocomotionSystem>(); TeleportationProvider teleProvider = xrRig.gameObject.AddComponent <TeleportationProvider>(); teleProvider.system = locoSys; // interactor var interactor = TestUtilities.CreateRayInteractor(); interactor.transform.SetParent(xrRig.cameraFloorOffsetObject.transform); interactor.lineType = XRRayInteractor.LineType.BezierCurve; // projectile curve // controller var controller = interactor.GetComponent <XRController>(); // create teleportation anchors var teleAnchor = TestUtilities.CreateTeleportAnchorPlane(); teleAnchor.interactionManager = manager; teleAnchor.teleportationProvider = teleProvider; teleAnchor.matchOrientation = MatchOrientation.None; // set teleportation anchor plane teleAnchor.transform.position = interactor.transform.forward + Vector3.down; teleAnchor.transform.Rotate(-90, 0, 0, Space.World); var controllerRecorder = TestUtilities.CreateControllerRecorder(controller, (recording) => { recording.AddRecordingFrame(0.0f, Vector3.zero, Quaternion.identity, true, false, false); recording.AddRecordingFrame(0.1f, Vector3.zero, Quaternion.identity, true, false, false); recording.AddRecordingFrame(float.MaxValue, Vector3.zero, Quaternion.identity, false, false, false); }); controllerRecorder.isPlaying = true; // wait for 1s to make sure the recorder simulates the action yield return(new WaitForSeconds(1f)); Vector3 cameraPosAdjustment = xrRig.rig.transform.up * xrRig.cameraInRigSpaceHeight; Assert.That(xrRig.cameraGameObject.transform.position == teleAnchor.transform.position + cameraPosAdjustment); Assert.That(xrRig.rig.transform.up == teleAnchor.transform.up); }
// Start is called before the first frame update void Start() { teleportationProvider = XRRig.GetComponent <TeleportationProvider>(); grabInteractable = GetComponent <XRGrabInteractable>(); grabInteractable.onSelectEnter.AddListener(EnableTeleportation); grabInteractable.onSelectExit.AddListener(DisableTeleportation); meshCollider = GetComponent <MeshCollider>(); teleportDestinations = GameObject.FindGameObjectsWithTag("TeleportDestination"); foreach (GameObject dest in teleportDestinations) { dest.gameObject.SetActive(false); } }
static void CreateLocomotionSystem() { var locomotionSystemGO = ObjectFactory.CreateGameObject("Locomotion System", typeof(LocomotionSystem), typeof(TeleportationProvider), typeof(SnapTurnProvider)); LocomotionSystem locomotionSystem = locomotionSystemGO.GetComponent <LocomotionSystem>(); TeleportationProvider teleportationProvider = locomotionSystemGO.GetComponent <TeleportationProvider>(); teleportationProvider.system = locomotionSystem; SnapTurnProvider snapTurnProvider = locomotionSystemGO.GetComponent <SnapTurnProvider>(); snapTurnProvider.system = locomotionSystem; snapTurnProvider.turnUsage = SnapTurnProvider.InputAxes.Primary2DAxis; }
static void CreateLocomotionSystem() { var locomotionSystemGO = ObjectFactory.CreateGameObject("Locomotion System", typeof(LocomotionSystem), typeof(TeleportationProvider), typeof(SnapTurnProvider)); LocomotionSystem locomotionSystem = locomotionSystemGO.GetComponent <LocomotionSystem>(); TeleportationProvider teleportationProvider = locomotionSystemGO.GetComponent <TeleportationProvider>(); teleportationProvider.system = locomotionSystem; SnapTurnProvider snapTurnProvider = locomotionSystemGO.GetComponent <SnapTurnProvider>(); snapTurnProvider.system = locomotionSystem; snapTurnProvider.enablePrimaryDevice = true; snapTurnProvider.PrimaryDeviceNode = XRNode.LeftHand; snapTurnProvider.enableSecondaryDevice = true; snapTurnProvider.SecondaryDeviceNode = XRNode.RightHand; }
protected virtual void Reset() { _xrRig = transform.CreateChild("__XRRig__").GetOrCreateComponent <QuickXRRig>(); _locomotionSystem = _xrRig.GetOrCreateComponent <LocomotionSystem>(); _teleportProvider = gameObject.GetOrCreateComponent <TeleportationProvider>(); _teleportProvider.system = _locomotionSystem; _continousMoveProvider = gameObject.GetOrCreateComponent <ActionBasedContinuousMoveProvider>(); _continousMoveProvider.system = _locomotionSystem; if (!_continousMoveProvider.leftHandMoveAction.action.IsValid()) { _continousMoveProvider.leftHandMoveAction = new InputActionProperty(InputManager.GetInputActionsDefault().FindAction("General/Move")); } _continousRotationProvider = gameObject.GetOrCreateComponent <ActionBasedContinuousTurnProvider>(); _continousRotationProvider.system = _locomotionSystem; if (!_continousRotationProvider.rightHandTurnAction.action.IsValid()) { _continousRotationProvider.rightHandTurnAction = new InputActionProperty(InputManager.GetInputActionsDefault().FindAction("General/RotateCamera")); } }
// Start is called before the first frame update private void Start() { SetDebug(); TurnOffTeleport(); _teleportationProvider = GetComponent <TeleportationProvider>(); var inputActionMap = actionAsset.FindActionMap("XRI LeftHand"); var activate = inputActionMap.FindAction("Teleport Mode Activate"); activate.Enable(); activate.performed += OnTeleportActivate; var cancel = inputActionMap.FindAction("Teleport Mode Cancel"); cancel.Enable(); cancel.performed += OnTeleportCancel; _thumbstick = inputActionMap.FindAction("Move"); _thumbstick.Enable(); }
/// <summary> /// Creates a new XRRig. /// </summary> public static XRRig CreateXRRig() { GameObject xrRigGO = new GameObject(); xrRigGO.name = "XR Rig"; XRRig xrRig = xrRigGO.AddComponent <XRRig>(); // add camera offset GameObject cameraOffsetGO = new GameObject(); cameraOffsetGO.name = "CameraOffset"; cameraOffsetGO.transform.SetParent(xrRig.transform, false); xrRig.cameraFloorOffsetObject = cameraOffsetGO; xrRig.transform.position = Vector3.zero; xrRig.transform.rotation = Quaternion.identity; // camera and track pose driver GameObject cameraGO = new GameObject(); cameraGO.name = "Camera"; Camera camera = cameraGO.AddComponent <Camera>(); cameraGO.transform.SetParent(cameraOffsetGO.transform, false); xrRig.cameraGameObject = cameraGO; XRDevice.DisableAutoXRCameraTracking(camera, true); LocomotionSystem locomotionSystem = xrRigGO.AddComponent <LocomotionSystem>(); TeleportationProvider teleportationProvider = xrRigGO.AddComponent <TeleportationProvider>(); locomotionSystem.xrRig = xrRig; teleportationProvider.system = locomotionSystem; return(xrRig); }
// Start is called before the first frame update void Start() { _teleportationProvider = GetComponent <TeleportationProvider>(); }