test(ai): 补测经 AiStateFragments 的跨模块状态撞名,State() 补引导注释
This commit is contained in:
@@ -114,5 +114,27 @@ namespace BaseGames.Tests.EditMode.AI
|
|||||||
var b = new BrainBuilder();
|
var b = new BrainBuilder();
|
||||||
Assert.Throws<System.ArgumentException>(() => AiStateFragments.AbilityOnce(b, "S", null));
|
Assert.Throws<System.ArgumentException>(() => AiStateFragments.AbilityOnce(b, "S", null));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void Fragments_Throw_WhenTwoModulesDeclareSameState()
|
||||||
|
{
|
||||||
|
// 守卫存在的真正理由:两个独立模块取了同名状态时,
|
||||||
|
// 后者的回调会静默覆盖前者。经原语声明必须直接报错。
|
||||||
|
var b = new BrainBuilder();
|
||||||
|
AiStateFragments.Locomotion(b, "Idle", LocomotionMode.Idle);
|
||||||
|
var ex = Assert.Throws<System.InvalidOperationException>(
|
||||||
|
() => AiStateFragments.Locomotion(b, "Idle", LocomotionMode.Patrol));
|
||||||
|
StringAssert.Contains("Idle", ex.Message);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void Fragments_Throw_WhenDifferentFragmentKindsCollide()
|
||||||
|
{
|
||||||
|
// 跨层撞名同样要挡:未发现层的 Locomotion 态与死亡层的 Ability 态重名。
|
||||||
|
var b = new BrainBuilder();
|
||||||
|
AiStateFragments.Locomotion(b, "Shared", LocomotionMode.Patrol);
|
||||||
|
Assert.Throws<System.InvalidOperationException>(
|
||||||
|
() => AiStateFragments.Ability(b, "Shared", "atk"));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,6 +16,10 @@ namespace BaseGames.AI
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 取一个状态,不存在则新建(宽松)。**只用于给别人已声明的态挂转换**。
|
||||||
|
/// 要声明一个态的行为(OnEnter/Tick/OnExit)请用 DeclareState()——它会挡住重名覆盖。
|
||||||
|
/// </summary>
|
||||||
public StateBuilder State(string name)
|
public StateBuilder State(string name)
|
||||||
{
|
{
|
||||||
if (!_states.TryGetValue(name, out var s))
|
if (!_states.TryGetValue(name, out var s))
|
||||||
|
|||||||
Reference in New Issue
Block a user