Exemple #1
0
    private void Update()
    {
        if (m_State == State.Moving || (s_ActiveTool != null && s_ActiveTool != this))
        {
            return;
        }

        if (m_BlinkLocomotionInput.blink.wasJustPressed)
        {
            s_ActiveTool = this;
            hideDefaultRay();
            m_BlinkVisuals.ShowVisuals();
        }
        else if (m_BlinkLocomotionInput.blink.wasJustReleased)
        {
            m_BlinkVisuals.HideVisuals();
            showDefaultRay();

            StartCoroutine(MoveTowardTarget(m_BlinkVisuals.locatorPosition));
        }
    }
    public void ProcessInput(ActionMapInput input, Action <InputControl> consumeControl)
    {
        var blinkInput = (BlinkLocomotion)input;

        if (m_State == State.Moving || (s_ActiveBlinkTool != null && s_ActiveBlinkTool != this))
        {
            return;
        }

        var viewerCamera = U.Camera.GetMainCamera();

        var yawValue     = blinkInput.yaw.value;
        var forwardValue = blinkInput.forward.value;

        if (Mathf.Abs(yawValue) > Mathf.Abs(forwardValue))
        {
            if (!Mathf.Approximately(yawValue, 0))
            {
                yawValue = yawValue * yawValue * Mathf.Sign(yawValue);

                viewerPivot.RotateAround(viewerCamera.transform.position, Vector3.up, yawValue * kRotationSpeed * Time.unscaledDeltaTime);
                consumeControl(blinkInput.yaw);
            }
        }
        else
        {
            if (!Mathf.Approximately(forwardValue, 0))
            {
                var forward = viewerCamera.transform.forward;
                forward.y = 0;
                forward.Normalize();
                forwardValue = forwardValue * forwardValue * Mathf.Sign(forwardValue);

                viewerPivot.Translate(forward * forwardValue * kMoveSpeed * Time.unscaledDeltaTime, Space.World);
                consumeControl(blinkInput.forward);
            }
        }

        if (blinkInput.blink.wasJustPressed && !m_BlinkVisuals.outOfMaxRange)
        {
            s_ActiveBlinkTool = this;
            hideDefaultRay(rayOrigin);
            lockRay(rayOrigin, this);

            m_BlinkVisuals.ShowVisuals();

            consumeControl(blinkInput.blink);
        }
        else if (s_ActiveBlinkTool == this && blinkInput.blink.wasJustReleased)
        {
            unlockRay(rayOrigin, this);
            showDefaultRay(rayOrigin);

            if (!m_BlinkVisuals.outOfMaxRange)
            {
                m_BlinkVisuals.HideVisuals();
                StartCoroutine(MoveTowardTarget(m_BlinkVisuals.locatorPosition));
            }
            else
            {
                m_BlinkVisuals.enabled = false;
            }

            consumeControl(blinkInput.blink);
        }
    }