fix(enemy): EnemyAiBrain 配置守卫不随重新启用蒸发,注册表消重

This commit is contained in:
2026-07-29 15:23:49 +08:00
parent 57cbaacf2c
commit 426fa3601d
2 changed files with 10 additions and 9 deletions
@@ -20,7 +20,10 @@ namespace BaseGames.Enemies
EnemyBase _enemy;
EnemyBrainContext _context;
AiRuntime _runtime;
bool _configValid;
/// <summary>调试显示用。配方路径返回资产名、脚本路径返回定义 id——两者是不同的
/// id 空间,**不要**拿它去 AiDefinitionRegistry 查表。</summary>
public string DefinitionId => _recipe != null ? _recipe.name : _definitionId;
public string CurrentStateName => _runtime != null ? _runtime.CurrentStateName : "(none)";
public bool IsSuspended => _runtime != null && _runtime.IsSuspended;
@@ -32,7 +35,8 @@ namespace BaseGames.Enemies
bool hasRecipe = _recipe != null;
bool hasId = !string.IsNullOrEmpty(_definitionId);
if (hasRecipe == hasId) // 都配了 或 都没配
_configValid = hasRecipe != hasId;
if (!_configValid)
{
// 根因暴露:配置歧义 / 漏配直接报错,不静默兜底。
Debug.LogError(
@@ -46,6 +50,10 @@ namespace BaseGames.Enemies
// 再触发入口状态 OnEnter(其会声明 locomotion 意图)。所有 Awake 先于任一 Start 执行。
void Start()
{
// 不依赖"禁用组件即跳过 Start"这一生命周期细节:组件若被事后重新启用,
// 配置仍然是错的,不能让它带着坏配置建图。
if (!_configValid) return;
IAiDefinition definition = _recipe != null
? (IAiDefinition)_recipe
: AiDefinitionRegistry.GetDefinition(_definitionId); // 不存在则抛异常