fix(enemy): EnemyAiBrain 配置守卫不随重新启用蒸发,注册表消重
This commit is contained in:
@@ -48,14 +48,7 @@ namespace BaseGames.AI
|
||||
}
|
||||
|
||||
/// <summary>取 id 对应的共享 AiGraph;不存在则显式抛错(根因暴露,不做兜底)。</summary>
|
||||
public static AiGraph GetGraph(string id)
|
||||
{
|
||||
EnsureBuilt();
|
||||
if (!_byId.TryGetValue(id, out var script))
|
||||
throw new InvalidOperationException(
|
||||
$"AiDefinitionRegistry: 未找到 AI 定义 id '{id}'。请确认存在 [AiDefinition(\"{id}\")] 的 AiScript 子类。");
|
||||
return script.GetOrBuildGraph();
|
||||
}
|
||||
public static AiGraph GetGraph(string id) => GetDefinition(id).GetOrBuildGraph();
|
||||
|
||||
/// <summary>取 id 对应的定义;不存在则显式抛错(根因暴露,不做兜底)。</summary>
|
||||
public static IAiDefinition GetDefinition(string id)
|
||||
|
||||
@@ -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); // 不存在则抛异常
|
||||
|
||||
Reference in New Issue
Block a user