feat(editor): 敌人 AI 配方脚手架向导;AssignModules 改名并失效缓存

- AiRecipeSO 新增 protected InvalidateGraph(),子类装配模块后调用以丢弃缓存图,
  避免改动要等到下次进 Play 才生效的静默陈旧图问题。
- PerceptionRecipeSO.SetModulesForTests 改名为 AssignModules(向导也要用它装配模块,
  旧名字具有误导性),并在装配后调用 InvalidateGraph。
- 新增 EnemyAiRecipeWizard:按 AssetFolderSpec 定名定路径创建感知型 AI 配方资产
  (Assets/_Game/Data/Enemies/{EnemyID}/ENM_{EnemyID}_Ai.asset),已存在则选中不覆盖。
- PerceptionRecipeSoTests 同步改名调用点,并新增测试钉住"装配后缓存必须失效"契约。
This commit is contained in:
2026-07-29 15:28:25 +08:00
parent 426fa3601d
commit ecdb0040cb
5 changed files with 108 additions and 3 deletions
@@ -25,7 +25,7 @@ namespace BaseGames.Tests.EditMode.AI
static PerceptionRecipeSO MakeE001Recipe()
{
var so = ScriptableObject.CreateInstance<PerceptionRecipeSO>();
so.SetModulesForTests(
so.AssignModules(
new DisguiseThenPatrol(),
new RushEngagement("e001_chase", RushExit.Committed));
return so;
@@ -80,5 +80,19 @@ namespace BaseGames.Tests.EditMode.AI
StringAssert.Contains("RushEngagement", ex.Message);
Object.DestroyImmediate(so);
}
[Test]
public void AssignModules_InvalidatesCachedGraph()
{
// 不失效的话,装配后拿到的还是旧图——静默的陈旧配置。
var so = MakeE001Recipe();
var first = so.GetOrBuildGraph();
so.AssignModules(new SinglePost(LocomotionMode.Idle),
new RushEngagement("other", RushExit.OnLostTarget));
var second = so.GetOrBuildGraph();
Assert.AreNotSame(first, second);
Assert.AreEqual(SinglePost.Post, second.EntryState); // 新模块生效
Object.DestroyImmediate(so);
}
}
}