Пример #1
0
        protected void Update()
        {
            if (_rtsCamera == null)
            {
                return; // no camera, bail!
            }
            if (AllowZoom)
            {
                var scroll = Input.GetAxisRaw(ZoomInputAxis);
                _rtsCamera.Distance -= scroll * ZoomSpeed * Time.unscaledDeltaTime;
            }

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

                    _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.unscaledDeltaTime;
                    }

                    if (AllowRotate)
                    {
                        var rot = Input.GetAxisRaw(RotateInputAxis);
                        _rtsCamera.Rotation += rot * RotateSpeed * Time.unscaledDeltaTime;
                    }
                }
            }

            if (AllowScreenEdgeMove && (!_rtsCamera.IsFollowing || ScreenEdgeMoveBreaksFollow))
            {
                var hasMovement = false;

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

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

                if (hasMovement && _rtsCamera.IsFollowing && ScreenEdgeMoveBreaksFollow)
                {
                    _rtsCamera.EndFollow();
                }
            }
        }
Пример #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);
                }
            }
        }