Ejemplo n.º 1
0
    protected void LateUpdate()
    {
        if (_rtsCamera == null)
        {
            return;
        }

        if (AllowZoom)
        {
            var scroll = Input.GetAxisRaw(ZoomInputAxis);

            _rtsCamera.Distance -= scroll * ZoomSpeed * Time.unscaledDeltaTime * 2;
        }

        if (Input.GetKey(MouseOrbitButton))
        {
            if (AllowPan)
            {
                var panX = -1 * Input.GetAxisRaw("Mouse X") * PanSpeed * Time.unscaledDeltaTime * 2;
                var panZ = -1 * Input.GetAxisRaw("Mouse Y") * PanSpeed * Time.unscaledDeltaTime * 2;

                _rtsCamera.AddToPosition(panX, 0, panZ);

                if (PanBreaksFollow && (Mathf.Abs(panX) > 0.001f || Mathf.Abs(panZ) > 0.001f))
                {
                    _rtsCamera.EndFollow();
                }
            }
        }

        if (Input.GetMouseButton(1))
        {
            if (AllowTilt)
            {
                var tilt = Input.GetAxisRaw(TiltInputAxis);
                _rtsCamera.Tilt -= tilt * TiltSpeed * Time.unscaledDeltaTime * 2;
            }

            if (AllowRotate)
            {
                var rot = Input.GetAxisRaw(RotateInputAxis);
                _rtsCamera.Rotation += rot * RotateSpeed * Time.unscaledDeltaTime * 2;
            }
        }
    }
Ejemplo n.º 2
0
    protected void Update()
    {
        if (_rtsCamera == null)
        {
            return; // no camera, bail!
        }
        if (AllowMove && (!_rtsCamera.IsFollowing || MovementBreaksFollow))
        {
            var hasMovement = false;

            var speed = MoveSpeed;
            if (AllowFastMove && (Input.GetKey(FastMoveKeyCode1) || Input.GetKey(FastMoveKeyCode2)))
            {
                speed = FastMoveSpeed;
            }

            var h = Input.GetAxisRaw(HorizontalInputAxis);
            if (Mathf.Abs(h) > 0.001f)
            {
                hasMovement = true;
                _rtsCamera.AddToPosition(h * speed * Time.unscaledDeltaTime, 0, 0);
            }

            var v = Input.GetAxisRaw(VerticalInputAxis);
            if (Mathf.Abs(v) > 0.001f)
            {
                hasMovement = true;
                _rtsCamera.AddToPosition(0, 0, v * speed * Time.unscaledDeltaTime);
            }

            if (hasMovement && _rtsCamera.IsFollowing && MovementBreaksFollow)
            {
                _rtsCamera.EndFollow();
            }
        }

        //

        if (AllowRotate)
        {
            if (RotateUsesInputAxis)
            {
                var rot = Input.GetAxisRaw(RotateInputAxis);
                if (Mathf.Abs(rot) > 0.001f)
                {
                    _rtsCamera.Rotation += rot * RotateSpeed * Time.unscaledDeltaTime;
                }
            }
            else
            {
                if (Input.GetKey(RotateLeftKey))
                {
                    _rtsCamera.Rotation += RotateSpeed * Time.unscaledDeltaTime;
                }
                if (Input.GetKey(RotateRightKey))
                {
                    _rtsCamera.Rotation -= RotateSpeed * Time.unscaledDeltaTime;
                }
            }
        }

        if (AllowZoom)
        {
            if (ZoomUsesInputAxis)
            {
                var zoom = Input.GetAxisRaw(ZoomInputAxis);
                if (Mathf.Abs(zoom) > 0.001f)
                {
                    _rtsCamera.Distance += zoom * ZoomSpeed * Time.unscaledDeltaTime;
                }
            }
            else
            {
                if (Input.GetKey(ZoomOutKey))
                {
                    _rtsCamera.Distance += ZoomSpeed * Time.unscaledDeltaTime;
                }
                if (Input.GetKey(ZoomInKey))
                {
                    _rtsCamera.Distance -= ZoomSpeed * Time.unscaledDeltaTime;
                }
            }
        }

        if (AllowTilt)
        {
            if (TiltUsesInputAxis)
            {
                var tilt = Input.GetAxisRaw(TiltInputAxis);
                if (Mathf.Abs(tilt) > 0.001f)
                {
                    _rtsCamera.Tilt += tilt * TiltSpeed * Time.unscaledDeltaTime;
                }
            }
            else
            {
                if (Input.GetKey(TiltUpKey))
                {
                    _rtsCamera.Tilt += TiltSpeed * Time.unscaledDeltaTime;
                }
                if (Input.GetKey(TiltDownKey))
                {
                    _rtsCamera.Tilt -= TiltSpeed * Time.unscaledDeltaTime;
                }
            }
        }

        //

        if (ResetKey != KeyCode.None)
        {
            if (Input.GetKeyDown(ResetKey))
            {
                _rtsCamera.ResetToInitialValues(IncludePositionOnReset, false);
            }
        }
    }
Ejemplo n.º 3
0
    protected void Update()
    {
        if (_rtsCamera == null)
        {
            return; // no camera, bail!
        }
        if (AllowZoom)
        {
            var scroll = Input.GetAxisRaw(ZoomInputAxis);
            _rtsCamera.Distance -= scroll * ZoomSpeed * Time.deltaTime;
        }

        if (Input.GetKey(MouseOrbitButton))
        {
            //if (AllowPan && (Input.GetKey(PanKey1) || Input.GetKey(PanKey2)))
            //{
            if (AllowPan)
            {
                // pan
                var panX = -1 * Input.GetAxisRaw("Mouse X") * PanSpeed * Time.deltaTime;
                var panZ = -1 * Input.GetAxisRaw("Mouse Y") * PanSpeed * Time.deltaTime;

                _rtsCamera.AddToPosition(panX, 0, panZ);

                if (PanBreaksFollow && (Mathf.Abs(panX) > 0.001f || Mathf.Abs(panZ) > 0.001f))
                {
                    _rtsCamera.EndFollow();
                }
            }
            //}
            //else
            //{
            //    // orbit

            //    if (AllowTilt)
            //    {
            //        var tilt = Input.GetAxisRaw(TiltInputAxis);
            //        _rtsCamera.Tilt -= tilt * TiltSpeed * Time.deltaTime;
            //    }

            //    if (AllowRotate)
            //    {
            //        var rot = Input.GetAxisRaw(RotateInputAxis);
            //        _rtsCamera.Rotation += rot * RotateSpeed * Time.deltaTime;
            //    }
            //}
        }
        if (Input.GetKey(KeyCode.Mouse3))
        {
            if (AllowRotate)
            {
                var rot = Input.GetAxisRaw(RotateInputAxis);
                _rtsCamera.Rotation += rot * RotateSpeed * Time.deltaTime;
            }
        }
        if (AllowScreenEdgeMove && (!_rtsCamera.IsFollowing || ScreenEdgeMoveBreaksFollow))
        {
            var hasMovement = false;

            if (Input.mousePosition.y > (Screen.height - ScreenEdgeBorderWidth))
            {
                hasMovement = true;
                _rtsCamera.AddToPosition(0, 0, MoveSpeed * Time.deltaTime);
            }
            else if (Input.mousePosition.y < ScreenEdgeBorderWidth)
            {
                hasMovement = true;
                _rtsCamera.AddToPosition(0, 0, -1 * MoveSpeed * Time.deltaTime);
            }

            if (Input.mousePosition.x > (Screen.width - ScreenEdgeBorderWidth))
            {
                hasMovement = true;
                _rtsCamera.AddToPosition(MoveSpeed * Time.deltaTime, 0, 0);
            }
            else if (Input.mousePosition.x < ScreenEdgeBorderWidth)
            {
                hasMovement = true;
                _rtsCamera.AddToPosition(-1 * MoveSpeed * Time.deltaTime, 0, 0);
            }

            if (hasMovement && _rtsCamera.IsFollowing && ScreenEdgeMoveBreaksFollow)
            {
                _rtsCamera.EndFollow();
            }
        }
    }