예제 #1
0
        private void UpdateInput(float dt)
        {
            // FIXME: need to consider UI interaction
            //if (EventSystem.current.IsPointerOverGameObject()) return;

            if (panActive && canUnfollow)
            {
                StopFollow();

                var v   = inputLookAxis.action.ReadValue <Vector2>() * dt * 3f;
                var pos = camPivot.Value;
                pos           += (tr.right * -v.x) + (tr.up * -v.y);
                camPivot.Value = pos;

                UpdateCameraPosition();
                return;                 // do not rotate or move when panning
            }

            if (rotateActive)
            {
                camRotator.Stop();

                var v = inputLookAxis.action.ReadValue <Vector2>();

                if (canRotate)
                {
                    tr.Rotate(0f, v.x * dt * rotateSpeed, 0f, Space.World);
                }

                if (canTilt)
                {
                    var r = tr.eulerAngles.x;
                    if (v.y < 0.0f && r < maxTilt)
                    {
                        tr.Rotate(-v.y * dt * tiltSpeed, 0f, 0f);
                    }
                    else if (v.y > 0.0f && r > minTilt)
                    {
                        tr.Rotate(-v.y * dt * tiltSpeed, 0f, 0f);
                    }
                }

                UpdateCameraPosition();
            }

            if (moveActive && canUnfollow)
            {
                var v = inputMoveAxis.action.ReadValue <Vector2>();
                if (v.x != 0.0f || v.y != 0.0f)
                {
                    StopFollow();

                    v *= dt * moveSpeed * (moveFaster ? moveFasterFactor : 1f);

                    var pos = camPivot.Value;
                    var y   = pos.y;
                    pos           += (tr.right * v.x) + (tr.forward * v.y);
                    pos.y          = y;
                    camPivot.Value = pos;

                    UpdateCameraPosition();
                }
            }
        }