refactor(enemy): 消费者切换到 IEnemyNavigator(Wander/Waypoints 去导航图化,调试面板简化)
This commit is contained in:
@@ -13,7 +13,7 @@ namespace BaseGames.Enemies
|
||||
/// 敌人基类(架构 07_EnemyModule §1)。
|
||||
/// 实现 IDamageable,为 Behavior Designer 任务提供统一虚方法接口。
|
||||
/// 包含:BD 接口、受击、死亡流程。
|
||||
/// ⚠️ _nav 字段类型为 IPathAgent(在 BaseGames.Enemies.Navigation 中实现具体类)。
|
||||
/// ⚠️ _nav 字段类型为 IEnemyNavigator(在 BaseGames.Enemies.Navigation 中实现具体类)。
|
||||
/// 实现 IPoolable:配合 PooledObject 支持对象池复用,避免频繁 Destroy/Instantiate。
|
||||
/// </summary>
|
||||
public class EnemyBase : MonoBehaviour, IDamageable, IPoolable
|
||||
@@ -60,10 +60,10 @@ namespace BaseGames.Enemies
|
||||
/// </summary>
|
||||
[SerializeField] private BaseGames.Core.Events.TransformEventChannelSO _onPlayerSpawned;
|
||||
|
||||
// ── 导航代理(IPathAgent;由 EnemyNavAgent 实现)───────────────────
|
||||
// ── 导航代理(IEnemyNavigator;由 GroundNavigator/FlyingNavigator 实现)─────
|
||||
// 通过接口引用,避免对 Navigation 程序集的直接依赖。
|
||||
// 由子类 / Inspector 注入,或者运行时 GetComponent<IPathAgent>() 获取。
|
||||
protected IPathAgent _nav;
|
||||
// 由子类 / Inspector 注入,或者运行时 GetComponent<IEnemyNavigator>() 获取。
|
||||
protected IEnemyNavigator _nav;
|
||||
|
||||
// 移动执行器(IEnemyLocomotion;由 EnemyLocomotion 在 Navigation 程序集实现,运行时发现)
|
||||
protected IEnemyLocomotion _locomotion;
|
||||
@@ -216,7 +216,7 @@ namespace BaseGames.Enemies
|
||||
}
|
||||
|
||||
// BD 任务访问接口(公共只读属性)────────────────────────────────
|
||||
public IPathAgent Nav => _nav;
|
||||
public IEnemyNavigator Nav => _nav;
|
||||
// 惰性发现兜底:关域重载后 Awake 设的实例字段可能残留为 null(编辑器快速迭代),
|
||||
// 首次访问时按需补发现,保证编辑器与构建下都不为空。
|
||||
public IEnemyLocomotion Locomotion => _locomotion ?? (_locomotion = GetComponentInChildren<IEnemyLocomotion>(true));
|
||||
@@ -256,7 +256,7 @@ namespace BaseGames.Enemies
|
||||
// ── BD 行为树接口(虚方法)────────────────────────────────────────
|
||||
|
||||
public virtual void MoveTo(Vector2 target)
|
||||
=> _nav?.RequestMoveTo(target);
|
||||
=> _nav?.MoveTowards(target);
|
||||
|
||||
public virtual void MoveInDirection(float dir)
|
||||
{
|
||||
@@ -284,7 +284,7 @@ namespace BaseGames.Enemies
|
||||
|
||||
public virtual void StopMovement()
|
||||
{
|
||||
_nav?.StopNavigation();
|
||||
_nav?.Stop();
|
||||
if (_movement != null) _movement.PendingInput.WantStop = true;
|
||||
}
|
||||
|
||||
@@ -547,7 +547,7 @@ namespace BaseGames.Enemies
|
||||
_stateObjs[EnemyStateType.KnockUp] = new EnemyKnockUpState();
|
||||
_stateObjs[EnemyStateType.Dead] = new EnemyDeadState();
|
||||
|
||||
_nav = GetComponent<IPathAgent>() ?? new NullPathAgent();
|
||||
_nav = GetComponent<IEnemyNavigator>() ?? new NullEnemyNavigator();
|
||||
_locomotion = GetComponentInChildren<IEnemyLocomotion>(true);
|
||||
if (_locomotion == null)
|
||||
Debug.LogError($"EnemyBase 未找到 EnemyLocomotion 组件:{name}", this);
|
||||
@@ -771,7 +771,7 @@ namespace BaseGames.Enemies
|
||||
public virtual void OnDespawn()
|
||||
{
|
||||
_abilities.InterruptAll(InterruptReason.Dead);
|
||||
_nav?.StopNavigation();
|
||||
_nav?.Stop();
|
||||
// GO 停用时 EnemyAiBrain.Update 自然停止,无需显式处理。
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user