示例#1
0
        private void Normal_Update()
        {
            if (!CheckCanControl())
            {
                return;
            }

            // 掉落坑检测
            if (CollisionSelf(PitLayer))
            {
                Fsm.ChangeState(States.FallInPit, StateTransition.Overwrite);
            }

            // 滚动检测
            if (CanRoll)
            {
                Fsm.ChangeState(States.Roll, StateTransition.Overwrite);
                return;
            }

            if (!GameManager.Instance.isMobile)
            {
                // ---- for pc ----
                var value = new Vector2(_inputMoveX, _inputMoveY);

                velocity = value * movingSpeed;

                // 瞄准
                if (UnityEngine.Camera.main != null)
                {
                    var mousePos = UnityEngine.Camera.main.ScreenToWorldPoint(UnityEngine.Input.mousePosition);
                    var position = transform.position;
                    FaceAngle = Mathf.Atan2(mousePos.y - position.y, mousePos.x - position.x) * 180 / Mathf.PI;
                    var vectorMouse = new Vector2(mousePos.x - position.x, mousePos.y - position.y).normalized;
                    if (PixelCameraFollower.Instance != null)
                    {
                        PixelCameraFollower.Instance.m_OffsetDir = vectorMouse;
                    }
                }

                // ---- for pc ----
            }
            else
            {
                // ---- for mobile ----
                velocity = _direction * movingSpeed;

                if (UiManager.Instance.joystickAtk.Direction != Vector2.zero)
                {
                    FaceAngle = Mathf.Atan2(UiManager.Instance.joystickAtk.Direction.y,
                                            UiManager.Instance.joystickAtk.Direction.x) * Mathf.Rad2Deg;
                }

                // ---- for mobile ----
            }

//            if (GameManager.Instance.isMobile)
//            {
//
//                if (UiManager.Instance.joystickAtk.Direction != Vector2.zero)
//                {
//                    FaceAngle = Mathf.Atan2(UiManager.Instance.joystickAtk.Direction.y,
//                                    UiManager.Instance.joystickAtk.Direction.x) * Mathf.Rad2Deg;
//                }
//
//            }
//            else
//            {
//                // ---- for pc ----
//                // 瞄准
//                var mousePos = UnityEngine.Camera.main.ScreenToWorldPoint(Input.mousePosition);
//
//                var position = transform.position;
//
//                FaceAngle = Mathf.Atan2(mousePos.y - position.y, mousePos.x - position.x) * 180 / Mathf.PI;
//                var vectorMouse = new Vector2(mousePos.x - position.x, mousePos.y - position.y).normalized;
//                if (PixelCameraFollower.Instance != null) PixelCameraFollower.Instance.m_OffsetDir = vectorMouse;
//                // ---- for pc ----
//            }

            if (FaceAngle < 0)
            {
                FaceAngle += 360f;
            }

            if (FaceAngle > 270 || FaceAngle < 90)
            {
                Facing = Facings.Right;
            }
            else
            {
                Facing = Facings.Left;
            }

            CurrentAngle = FaceAngle;

            if (CurrWeapon != null)
            {
                CurrWeapon.SetRotation(FaceAngle);
            }

            if (!PointerIsNull)
            {
                pointerSpriteHolder.localRotation = Quaternion.Euler(0, 0, FaceAngle + 45);
            }

            bool fire;

            if (GameManager.Instance.isMobile)
            {
                fire = allowAttack && CurrWeapon != null &&
                       (Mathf.Abs(UiManager.Instance.joystickAtk.Direction.x) >= 0.5f ||
                        Mathf.Abs(UiManager.Instance.joystickAtk.Direction.y) >= 0.5f);
            }
            else
            {
                fire = (Input.GetButtonDown(playerNumber, InputAction.Fire) ||
                        Input.GetButton(playerNumber, InputAction.Fire)) &&
                       CurrWeapon != null && allowAttack && !UiManager.CheckGuiRaycastObjects();
            }

            var w = CurrWeapon;

            if (fire)
            {
                Attack(ref w);
            }
            else if (CurrWeapon != null)
            {
                CurrWeapon.StopAttack();
            }

            // 监听加速
            if (Input.GetButtonDown(playerNumber, InputAction.SpeedUp) ||
                Input.GetButton(playerNumber, InputAction.SpeedUp))
            {
                movingSpeed = limitSpeed;
            }
            else
            {
                movingSpeed = DefaultSpeed;
            }

            // 闪避技能释放
            if (Input.GetButtonDown(playerNumber, InputAction.DisplacementSkill) ||
                Input.GetButton(playerNumber, InputAction.DisplacementSkill))
            {
                TryUseSkill(GameManager.Instance.PlayerInfo.skillPack.GetDisplacementSkill());
            }

            // 主技能释放
            if (Input.GetButtonDown(playerNumber, InputAction.FirstSkill) ||
                Input.GetButton(playerNumber, InputAction.FirstSkill))
            {
                TryUseSkill(GameManager.Instance.PlayerInfo.skillPack.skillDetails[0]);
            }

            // 主技能释放
            if (Input.GetButtonDown(playerNumber, InputAction.SecondSkill) ||
                Input.GetButton(playerNumber, InputAction.SecondSkill))
            {
                TryUseSkill(GameManager.Instance.PlayerInfo.skillPack.skillDetails[1]);
            }

            // 主技能释放
            if (Input.GetButtonDown(playerNumber, InputAction.ThirdSkill) ||
                Input.GetButton(playerNumber, InputAction.ThirdSkill))
            {
                TryUseSkill(GameManager.Instance.PlayerInfo.skillPack.skillDetails[2]);
            }
        }