feat(ai): AiDefinitionRegistry——反射按id提供共享AiGraph(关域重载重置)
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
using NUnit.Framework;
|
||||
using BaseGames.AI;
|
||||
|
||||
namespace BaseGames.Tests.EditMode.AI
|
||||
{
|
||||
// 顶层测试定义,供反射注册表发现
|
||||
[AiDefinition("__test_grunt")]
|
||||
internal sealed class TestGruntAi : AiScript
|
||||
{
|
||||
protected override void Build(BrainBuilder b)
|
||||
{
|
||||
b.Entry("A");
|
||||
b.State("A").To("B").When(c => c.Sensor.SeesPlayer(), "SeesPlayer");
|
||||
b.State("B");
|
||||
}
|
||||
}
|
||||
|
||||
public class AiDefinitionRegistryTests
|
||||
{
|
||||
[Test]
|
||||
public void Has_FindsRegisteredDefinition()
|
||||
{
|
||||
Assert.IsTrue(AiDefinitionRegistry.Has("__test_grunt"));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetGraph_ResolvesById()
|
||||
{
|
||||
var g = AiDefinitionRegistry.GetGraph("__test_grunt");
|
||||
Assert.AreEqual("A", g.EntryState);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetGraph_SameId_ReturnsSharedInstance()
|
||||
{
|
||||
Assert.AreSame(
|
||||
AiDefinitionRegistry.GetGraph("__test_grunt"),
|
||||
AiDefinitionRegistry.GetGraph("__test_grunt"));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetGraph_UnknownId_Throws()
|
||||
{
|
||||
Assert.Throws<System.InvalidOperationException>(
|
||||
() => AiDefinitionRegistry.GetGraph("__nope__"));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 830591c077a45b54f9f56e6debdb035b
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user