using UnityEngine; namespace BaseGames.Player.States { /// 闲置状态。默认入口状态,播放 Idle 动画。 public class IdleState : PlayerStateBase { public IdleState(PlayerController owner) : base(owner) { } public override void OnStateEnter() { if (AnimCfg?.Idle != null) Anim.Play(AnimCfg.Idle); Move?.ZeroHorizontalVelocity(); // 落地时重置空中能力计数器及抓墙记录 Owner.ResetAirJumps(); Owner.GetState()?.ResetDashCharge(); Owner.GetState()?.ResetWallGrab(); Owner.SetPostWallJump(false); } public override void OnStateUpdate() { if (!Move.IsGrounded) { _owner.TransitionTo(_owner.GetState()); return; } // 单向平台穿落:↓ + 跳跃键,优先于普通跳跃,避免误消耗跳跃缓冲 if (Move.OnOneWayPlatform && Input.MoveInput.y < -0.5f && Buffer.ConsumeJump()) { Move.DropThroughPlatform(); _owner.TransitionTo(_owner.GetState()); return; } if (Buffer.ConsumeJump()) { _owner.TransitionTo(_owner.GetState()); return; } // 地面攻击:Move Y > 0 → 上劈;其余 → 普通连击 if (Buffer.ConsumeAttack()) { if (Input.MoveInput.y > 0.5f) _owner.TransitionTo(_owner.GetState()); else _owner.TransitionTo(_owner.GetState()); return; } // 地面冲刺:先确认能力与冷却均满足,再消耗缓冲,避免无操作时静默吃掉输入 var ds = Owner.GetState(); if (ds != null && ds.CanDash && Stats != null && Stats.HasAbility(AbilityType.Dash) && Buffer.ConsumeDash()) { _owner.TransitionTo(ds); return; } if (Mathf.Abs(Input.MoveInput.x) > 0.1f) { _owner.TransitionTo(_owner.GetState()); } } public override void OnStateFixedUpdate() { // 离地检测(与 CheckGrounded 同帧在 FixedUpdate 中执行,立即响应离地事件) // OnStateUpdate 中仍保留同样的检测作为跨帧补充,两者不会发生双重转换: // 本帧若在 FixedUpdate 中转换到 FallState,Update 调用的将是 FallState.OnStateUpdate()。 if (!Move.IsGrounded) _owner.TransitionTo(_owner.GetState()); } } }