using UnityEngine; namespace BaseGames.Player.States { /// /// 壁滑状态(架构 05_PlayerModule §2)。 /// 需有 PlayerWallDetector.IsTouchingWall == true 才能进入; /// 限制下落速度为 WallSlideSpeed;按跳跃则切换到 WallJumpState。 /// public class WallSlideState : PlayerStateBase { public WallSlideState(PlayerController owner) : base(owner) { } public override void OnStateEnter() { if (AnimCfg?.WallSlide != null) Anim?.Play(AnimCfg.WallSlide); Input.JumpStartedEvent += OnJumpPressed; } public override void OnStateExit() { Input.JumpStartedEvent -= OnJumpPressed; } public override void OnStateUpdate() { // 离开墙壁 → 下落 if (Owner.WallDetector == null || !Owner.WallDetector.IsTouchingWall) { Owner.TransitionTo(Owner.GetState()); return; } // 着地 → 闲置 if (Move.IsGrounded) { Owner.TransitionTo(Owner.GetState()); return; } } public override void OnStateFixedUpdate() { // 限制下落速度(壁滑缓慢下落) Move?.ApplyWallSlide(); } private void OnJumpPressed() { Owner.TransitionTo(Owner.GetState()); } } }