fix(ai): AiRuntime 自转换设为no-op(根治死亡双发Died再入) + EnemyBase.OnSpawn复位brain.enabled + 测试

Switch 对 target==当前态直接 no-op(不重跑Exit/Enter),循环改为 if(Switch(t))return true;
OnSpawn 复用时恢复被 QuotaManager 裁剪禁用的 brain。

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-07-03 16:26:28 +08:00
co-authored by Claude Opus 4.8
parent d38c6e35bb
commit 63e241af92
3 changed files with 23 additions and 4 deletions
@@ -174,6 +174,23 @@ namespace BaseGames.Tests.EditMode.AI
Assert.AreEqual("Flee", rt.CurrentStateName);
}
[Test]
public void EventSelfTransition_DoesNotReenter()
{
var b = new BrainBuilder();
b.Entry("Dead");
int enterCount = 0;
b.State("Dead").OnEnter(c => enterCount++);
b.Global().To("Dead").OnEvent(AiSignal.Died);
var ctx = new FakeAiContext();
var rt = new AiRuntime(b.Build(), ctx);
// 构造即进入 Dead → enterCount==1
rt.Send(AiSignal.Died);
rt.Tick(0.1f); // 已在 Dead,自转换应 no-op,不再 +1
Assert.AreEqual(1, enterCount);
Assert.AreEqual("Dead", rt.CurrentStateName);
}
[Test]
public void TwoRuntimes_ShareGraph_IndependentStateAndTimer()
{