예제 #1
0
        void Update()
        {
            if (IsConfigured() == false)
            {
                return;
            }

            currentController = GetControllerTransform();

            // Complete active teleport transitions.
            if (IsTeleporting)
            {
                visualizer.OnTeleport();
                // Update the visualization.
                visualizer.UpdateSelection(currentController, selectionResult);
                return;
            }

            // If rotation is allowed, handle player rotations.
            if (allowRotation)
            {
                HandlePlayerRotations();
            }

            // If a teleport selection session has not started, check the appropriate
            // trigger to see if one should start.
            if (selectionIsActive == false)
            {
                if (teleportStartTrigger.TriggerActive())
                {
                    //if player is not ready for teleport then return
                    if (Player.instance.currentState != Player.PlayerState.None)
                    {
                        return;
                    }
                    StartTeleportSelection();
                }
            }

            // Get the current selection result from the detector.
            // float playerHeight = DetectPlayerHeight();
            float playerHeight = Player.instance.playerHeight;

            selectionResult = detector.DetectSelection(currentController, playerHeight);

            // Update the visualization.
            visualizer.UpdateSelection(currentController, selectionResult);

            // If not actively teleporting, just return.
            if (selectionIsActive == false)
            {
                return;
            }

            // Check for the optional cancel trigger.
            if (teleportCancelTrigger != null &&
                teleportCancelTrigger.TriggerActive() &&
                !teleportCommitTrigger.TriggerActive())
            {
                EndTeleportSelection();
                return;
            }
            Vector3 nextPlayerPosition = Vector3.zero;

            // When trigger deactivates we finish the teleport.
            if (selectionIsActive && teleportCommitTrigger.TriggerActive())
            {
                if (selectionResult.selectionIsValid)
                {
                    detector.EndSelection();
                    visualizer.EndSelection();


                    nextPlayerPosition = new Vector3(
                        selectionResult.selection.x,
                        selectionResult.selection.y + playerHeight,
                        selectionResult.selection.z);

                    // Start a transition to move the player.
                    //transition.StartTransition(
                    //  player,
                    //  currentController,
                    //  nextPlayerPosition);
                    if (Player.instance.visualPlayer)
                    {
                        Player.instance.visualPlayer.transform.DOMove(nextPlayerPosition, 1f);
                    }
                    player.DOMove(nextPlayerPosition, 1f).OnComplete(() => { EndTeleportSelection(); });
                }

                //    EndTeleportSelection();
            }
        }
예제 #2
0
        void Update()
        {
            if (IsConfigured() == false)
            {
                return;
            }

            currentController = GetControllerTransform();

            // Complete active teleport transitions.
            if (IsTeleporting)
            {
                visualizer.OnTeleport();
                // Update the visualization.
                visualizer.UpdateSelection(currentController, selectionResult);
                return;
            }

            // If rotation is allowed, handle player rotations.
            if (allowRotation)
            {
                HandlePlayerRotations();
            }

            // If a teleport selection session has not started, check the appropriate
            // trigger to see if one should start.
            if (selectionIsActive == false)
            {
                if (teleportStartTrigger.TriggerActive())
                {
                    StartTeleportSelection();
                }
            }

            // Get the current selection result from the detector.
            float playerHeight = DetectPlayerHeight();

            selectionResult = detector.DetectSelection(currentController, playerHeight);

            // Update the visualization.
            visualizer.UpdateSelection(currentController, selectionResult);

            // If not actively teleporting, just return.
            if (selectionIsActive == false)
            {
                return;
            }

            // Check for the optional cancel trigger.
            if (teleportCancelTrigger != null &&
                teleportCancelTrigger.TriggerActive() &&
                !teleportCommitTrigger.TriggerActive())
            {
                EndTeleportSelection();
                return;
            }

            // When trigger deactivates we finish the teleport.
            if (selectionIsActive && teleportCommitTrigger.TriggerActive())
            {
                if (selectionResult.selectionIsValid)
                {
                    Vector3 nextPlayerPosition = new Vector3(
                        selectionResult.selection.x,
                        selectionResult.selection.y + playerHeight,
                        selectionResult.selection.z);

                    // Start a transition to move the player.
                    transition.StartTransition(
                        player,
                        currentController,
                        nextPlayerPosition);
                }

                EndTeleportSelection();
            }
        }