using UnityEngine; namespace BaseGames.Player.States { /// /// 蹬墙跳状态(架构 05_PlayerModule §2)。 /// 从 WallSlideState 进入;施加背墙方向的水平 + 垂直速度; /// 短暂锁定水平输入后转为 FallState。 /// public class WallJumpState : PlayerStateBase { private float _inputLockTimer; private int _wallDir; public WallJumpState(PlayerController owner) : base(owner) { } public override void OnStateEnter() { // 记录墙壁方向(跳跃反向) _wallDir = Owner.WallDetector != null ? Owner.WallDetector.WallDirection : 0; if (_wallDir == 0) _wallDir = -Owner.FacingDirection; // 施加蹬墙跳速度 Move?.WallJump(_wallDir); // 锁定水平输入 _inputLockTimer = Cfg.WallJumpInputLockDuration; // 播放跳跃动画(复用跳跃动画) if (AnimCfg?.Jump != null) Anim?.Play(AnimCfg.Jump); Input.JumpCancelledEvent += OnJumpCancelled; } public override void OnStateExit() { Input.JumpCancelledEvent -= OnJumpCancelled; } public override void OnStateUpdate() { // 上升结束 → 下落 if (!Move.IsRising) { Owner.TransitionTo(Owner.GetState()); return; } } public override void OnStateFixedUpdate() { _inputLockTimer -= Time.fixedDeltaTime; // 输入锁结束后允许水平控制 if (_inputLockTimer <= 0f && Mathf.Abs(Input.MoveInput.x) > 0.01f) Move?.Move(Input.MoveInput.x * Cfg.RunSpeed); } private void OnJumpCancelled() => Move?.CutJump(); } }