feat(enemy): EnemyLocomotion 按模式驱动步态动画(Idle/Walk/Alert/Run)

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-07-10 13:33:16 +08:00
co-authored by Claude Opus 4.8
parent 087aa96ca6
commit 347d0e2f50
2 changed files with 23 additions and 0 deletions
+15
View File
@@ -487,6 +487,21 @@ namespace BaseGames.Enemies
} }
} }
/// <summary>按当前移动模式播放步态动画(由 EnemyLocomotion 在模式变化时调用)。</summary>
public void PlayLocomotionClip(LocomotionMode mode)
{
if (_animancer == null || _animConfig == null) return;
var clip = mode switch
{
LocomotionMode.Idle => _animConfig.Idle,
LocomotionMode.Patrol => _animConfig.Walk,
LocomotionMode.Face => _animConfig.Alert,
LocomotionMode.Approach => _animConfig.Run,
_ => null,
};
if (clip != null) _animancer.Play(clip);
}
// ── 动画事件钩子(由 EnemyAnimationEvents 调用)──────────────────── // ── 动画事件钩子(由 EnemyAnimationEvents 调用)────────────────────
/// <summary> /// <summary>
@@ -18,6 +18,8 @@ namespace BaseGames.Enemies
private LocomotionMode _mode = LocomotionMode.Idle; private LocomotionMode _mode = LocomotionMode.Idle;
private Transform _approachTarget; private Transform _approachTarget;
private Vector2 _facePoint; private Vector2 _facePoint;
private LocomotionMode _gaitMode;
private bool _gaitInit;
public LocomotionMode CurrentMode => _mode; public LocomotionMode CurrentMode => _mode;
public bool IsMoving => _enemy != null && _enemy.Nav != null && _enemy.Nav.IsMoving; public bool IsMoving => _enemy != null && _enemy.Nav != null && _enemy.Nav.IsMoving;
@@ -69,6 +71,12 @@ namespace BaseGames.Enemies
private void Update() private void Update()
{ {
if (_enemy == null) return; if (_enemy == null) return;
if (!_gaitInit || _gaitMode != _mode)
{
_enemy.PlayLocomotionClip(_mode);
_gaitMode = _mode;
_gaitInit = true;
}
switch (_mode) switch (_mode)
{ {
case LocomotionMode.Idle: case LocomotionMode.Idle: