Files
zeling_v2/Assets/_Game/Scripts/Player/States/ParryState.cs

55 lines
1.7 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
namespace BaseGames.Player.States
{
/// <summary>
/// 弹反预备状态(架构 05_PlayerModule §2完整实现在 Week 6
/// 开启 ParrySystem 弹反窗口,播放 ParryStart 动画;
/// 成功弹反后 ParrySystem.ConsumeParry() 返回 trueHurtBox 不处理该次伤害。
/// </summary>
public class ParryState : PlayerStateBase
{
public ParryState(PlayerController owner) : base(owner) { }
public override void OnStateEnter()
{
// 开启弹反窗口HurtBox.ReceiveDamage 步骤 2 查询)
Owner.Parry?.OpenParryWindow();
// 停止移动
Move?.ZeroHorizontalVelocity();
// 播放弹反预备动画
if (AnimCfg?.ParryStart != null)
{
var state = Anim?.Play(AnimCfg.ParryStart);
if (state != null)
{
state.Events(this).OnEnd = OnParryEnd;
return;
}
}
// 无动画则立即结束
OnParryEnd();
}
public override void OnStateExit()
{
// 确保弹反窗口关闭(无论是否成功)
Owner.Parry?.CloseParryWindow();
}
private void OnParryEnd()
{
Owner.TransitionTo(Owner.GetState<IdleState>());
}
public override void OnStateFixedUpdate()
{
// 弹反预备期间无水平输入,仍需每帧调用 Move(0) 叠加 _platformVelocity.x
// 使玩家在移动平台上弹反时随平台同步移动。
if (Move != null && Move.IsGrounded)
Move.Move(0f);
}
}
}