Esempio n. 1
0
 private void Awake()
 {
     leftHand             = this.FindComponent <ActionBasedControllerManager>("XR Origin/Camera Offset/LeftHand");
     rightHand            = this.FindComponent <ActionBasedControllerManager>("XR Origin/Camera Offset/RightHand");
     _interactionManager  = this.FindComponent <XRInteractionManager>("XR Interaction Manager");
     locomotionSystem     = this.FindGameObject("Locomotion System");
     _mainCamera          = this.FindComponent <Camera>("XR Origin/Camera Offset/Main Camera");
     leftXRRayInteractor  = LeftController.GetComponent <XRRayInteractor>();
     rightXRRayInteractor = RightController.GetComponent <XRRayInteractor>();
 }
Esempio n. 2
0
        private void Start()
        {
            this.rotationX = Camera.main.transform.localRotation.eulerAngles.x;
            this.rotationY = Camera.main.transform.localRotation.eulerAngles.y;

            // Head
            this.headTrackedPoseDriver         = this.GetComponentInChildren <TrackedPoseDriver>();
            this.headTrackedPoseDriver.enabled = false;
            this.headTransform = this.headTrackedPoseDriver.transform;

            var actionBasedControllerManagers = this.GetComponentsInChildren <ActionBasedControllerManager>();

            // Left Hand
            this.leftHand = actionBasedControllerManagers[0].transform;
            this.leftHandActionManager = actionBasedControllerManagers[0];

            var leftActionBasedControllers = this.leftHand.GetComponentsInChildren <ActionBasedController>(true);

            this.leftHandBase     = leftActionBasedControllers[0];
            this.leftHandTeleport = leftActionBasedControllers[1];

            // Right Hand
            this.rightHand = actionBasedControllerManagers[1].transform;
            this.rightHandActionManager = actionBasedControllerManagers[1];

            var rightActionBasedControllers = this.rightHand.GetComponentsInChildren <ActionBasedController>(true);

            this.rightHandBase     = rightActionBasedControllers[0];
            this.rightHandTeleport = rightActionBasedControllers[1];

            // Left Hand XR Ray Interactor
            this.leftHandTeleportXRRayInteractor = this.leftHandBase.GetComponent <XRRayInteractor>();

            // Right Hand Teleport XR Ray Interactor
            this.rightHandTeleportXRRayInteractor = this.rightHandTeleport.GetComponent <XRRayInteractor>();
            this.rightHandTeleportXRRayInteractor.acceleration = this.teleportGravity;
            this.rightHandTeleportXRRayInteractor.velocity     = this.teleportVelocity;

            // Overriding Input Actions to use Pancake Versions
            if (this.pancakeInputActions != null)
            {
                this.rightHandActionManager.teleportModeActivate.Set(this.pancakeInputActions.FindAction("Teleport Activate"));
                this.rightHandActionManager.teleportModeCancel.Set(this.pancakeInputActions.FindAction("Teleport Cancel"));
                this.rightHandTeleport.selectAction = new InputActionProperty(this.pancakeInputActions.FindAction("Teleport Select"));

                this.leftHandBase.selectAction          = new InputActionProperty(this.pancakeInputActions.FindAction("Select"));
                this.leftHandBase.activateAction        = new InputActionProperty(this.pancakeInputActions.FindAction("Activate"));
                this.leftHandBase.translateAnchorAction = new InputActionProperty(this.pancakeInputActions.FindAction("Translate Anchor"));
            }

            if (this.leftHandTeleportXRRayInteractor)
            {
                this.leftHandTeleportXRRayInteractor.selectActionTrigger = XRBaseControllerInteractor.InputTriggerType.Toggle;
            }

            // Turning off all the hand meshes
            if (this.disableControllerModels)
            {
                this.leftHandBase.modelPrefab      = null;
                this.leftHandTeleport.modelPrefab  = null;
                this.rightHandBase.modelPrefab     = null;
                this.rightHandTeleport.modelPrefab = null;

                DestoryControllerModel(this.leftHandBase);
                DestoryControllerModel(this.leftHandTeleport);
                DestoryControllerModel(this.rightHandBase);
                DestoryControllerModel(this.rightHandTeleport);
            }

            // Making sure the main xr ray interactor doesn't have a line renderer
            if (this.disableLineRenderer)
            {
                this.StartCoroutine(DisableLineRenderer());
            }

            // Setting up the reticle events
            this.reticleRayInteractor.hoverEntered.AddListener(this.HoverEntered);
            this.reticleRayInteractor.hoverExited.AddListener(this.HoverExited);
            this.reticleRayInteractor.selectEntered.AddListener(this.SelectEntered);
            this.reticleRayInteractor.selectExited.AddListener(this.SelectExited);

            IEnumerator DisableLineRenderer()
            {
                yield return(null);

                var lineVisual = this.leftHandBase.GetComponent <XRInteractorLineVisual>();

                if (lineVisual)
                {
                    lineVisual.enabled = false;
                }

                var lineRenderer = this.leftHandBase.GetComponent <LineRenderer>();

                if (lineRenderer)
                {
                    lineRenderer.enabled = false;
                }
            }

            void DestoryControllerModel(ActionBasedController controller)
            {
                for (int i = 0; i < controller.transform.childCount; i++)
                {
                    var child = controller.transform.GetChild(i);

                    if (child.name.EndsWith(" Model"))
                    {
                        child.DestroyAllChildren();
                    }
                }
            }
        }