Files
zeling_v2/Assets/_Game/Scripts/Enemies/States/EnemyHurtState.cs

27 lines
931 B
C#
Raw Permalink 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.Enemies.States
{
/// <summary>
/// 受击状态。播放受击动画,动画结束后自动回到 Controlled。
/// 原 EnemyBase.ForceState 中的 Hurt if-else 逻辑已迁移至此。
/// </summary>
public sealed class EnemyHurtState : IEnemyState
{
public EnemyStateType StateType => EnemyStateType.Hurt;
public void Enter(EnemyBase owner)
{
if (owner.Animancer == null || owner.AnimConfig?.Hurt == null) return;
var animState = owner.Animancer.Play(owner.AnimConfig.Hurt);
animState.Events(owner).OnEnd = () =>
{
// 只在仍处于 Hurt 时才回 Controlled避免 Die 时被覆盖
if (owner.CurrentState == EnemyStateType.Hurt)
owner.ForceState(EnemyStateType.Controlled);
};
}
public void Exit(EnemyBase owner) { }
}
}