feat: trigger fighter behavior from lobby action button

This commit is contained in:
ud18010
2026-07-30 17:00:31 +08:00
parent 03cee1036d
commit e9efa8a567
9 changed files with 674 additions and 0 deletions
@@ -0,0 +1,102 @@
using System.Linq;
using NUnit.Framework;
using UnityEngine;
using XGame.ActorBehavior;
using XGame.VirtualInput;
using XWorld.Framework.ActorBehavior;
public sealed class LobbyActorBehaviorRuntimeTests
{
[Test]
public void RegisterSelfActor_DefaultsCatalogToFighter()
{
var runtime = new LobbyActorBehaviorRuntime();
runtime.RegisterCatalog(CreateFighterCatalog());
runtime.RegisterOrUpdateActor(10, Vector3.zero, Vector3.forward);
Assert.That(runtime.SwitchActorCatalog(10, LobbyActorBehaviorRuntime.DefaultCatalogType), Is.True);
}
[Test]
public void Skill1Tap_StartsQuantao01AndEmitsPresentationEvents()
{
var runtime = new LobbyActorBehaviorRuntime();
runtime.RegisterCatalog(CreateFighterCatalog());
runtime.RegisterOrUpdateActor(10, Vector3.zero, Vector3.forward);
BehaviorStartResult result = runtime.HandleActionButton(
CreateButtonEvent(ActionButtonId.Skill1, ActionButtonPhase.Tap, Vector2.zero),
10,
Vector3.forward);
BehaviorEvent[] events = runtime.DrainEvents().ToArray();
Assert.That(result.Success, Is.True);
Assert.That(events.Any(e => e.Kind == BehaviorEventKind.TimelineAnimation && e.Animation == "140_skill01a_qt"), Is.True);
Assert.That(events.Any(e => e.Kind == BehaviorEventKind.TimelineEffect && e.Prefab.Contains("9110004_zhujue_quantao_skill01a")), Is.True);
}
[Test]
public void PrimaryTap_DoesNotStartQuantao01()
{
var runtime = new LobbyActorBehaviorRuntime();
runtime.RegisterCatalog(CreateFighterCatalog());
runtime.RegisterOrUpdateActor(10, Vector3.zero, Vector3.forward);
BehaviorStartResult result = runtime.HandleActionButton(
CreateButtonEvent(ActionButtonId.Primary, ActionButtonPhase.Tap, Vector2.zero),
10,
Vector3.forward);
Assert.That(result.Success, Is.False);
Assert.That(result.Error, Is.EqualTo("button ignored"));
Assert.That(runtime.DrainEvents().Any(e => e.BehaviorId == LobbyActorBehaviorRuntime.SecondaryABehaviorId), Is.False);
}
[Test]
public void Skill1Release_DoesNotStartQuantao01Again()
{
var runtime = new LobbyActorBehaviorRuntime();
runtime.RegisterCatalog(CreateFighterCatalog());
runtime.RegisterOrUpdateActor(10, Vector3.zero, Vector3.forward);
BehaviorStartResult result = runtime.HandleActionButton(
CreateButtonEvent(ActionButtonId.Skill1, ActionButtonPhase.Release, Vector2.right),
10,
Vector3.forward);
Assert.That(result.Success, Is.False);
Assert.That(result.Error, Is.EqualTo("button ignored"));
Assert.That(runtime.DrainEvents().Any(e => e.BehaviorId == LobbyActorBehaviorRuntime.SecondaryABehaviorId), Is.False);
}
private static ActionButtonEvent CreateButtonEvent(ActionButtonId buttonId, ActionButtonPhase phase, Vector2 direction)
{
return new ActionButtonEvent(buttonId, phase, Vector2.zero, Vector2.zero, direction, direction.magnitude, 0f, false, 1);
}
private static BehaviorConfigCatalog CreateFighterCatalog()
{
return BehaviorConfigCatalog.LoadFromJson(
"fighter",
@"{
""type"": ""fighter"",
""version"": 1,
""behaviors"": [
{
""id"": ""quantao01"",
""duration"": 1.0,
""canBeInterrupted"": true,
""input"": ""DirectionOrTarget"",
""timeline"": [
{ ""time"": 0.0, ""kind"": ""Animation"", ""animation"": ""140_skill01a_qt"", ""duration"": 1.0 },
{ ""time"": 0.0, ""kind"": ""Effect"", ""prefab"": ""Assets/Game/Art/Effect/Prefab/skill/9110004_zhujue_quantao_skill01a.prefab"", ""duration"": 1.0 }
],
""logicEffects"": []
}
]
}",
@"{ ""type"": ""fighter"", ""version"": 1, ""flyObjects"": [] }",
@"{ ""type"": ""fighter"", ""version"": 1, ""buffs"": [] }");
}
}