修复技能输入并更新战斗资源
This commit is contained in:
@@ -70,6 +70,33 @@ public sealed class LobbyActorBehaviorRuntimeTests
|
||||
Assert.That(runtime.DrainEvents().Any(e => e.BehaviorId == LobbyActorBehaviorRuntime.SecondaryABehaviorId), Is.False);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Skill1Tap_DoesNotRestartWhileSkillIsActive()
|
||||
{
|
||||
var runtime = new LobbyActorBehaviorRuntime();
|
||||
runtime.RegisterCatalog(CreateFighterCatalog());
|
||||
runtime.RegisterOrUpdateActor(10, Vector3.zero, Vector3.forward);
|
||||
|
||||
BehaviorStartResult first = runtime.HandleActionButton(
|
||||
CreateButtonEvent(ActionButtonId.Skill1, ActionButtonPhase.Tap, Vector2.zero),
|
||||
10,
|
||||
Vector3.forward);
|
||||
runtime.DrainEvents();
|
||||
|
||||
BehaviorStartResult second = runtime.HandleActionButton(
|
||||
CreateButtonEvent(ActionButtonId.Skill1, ActionButtonPhase.Tap, Vector2.zero),
|
||||
10,
|
||||
Vector3.forward);
|
||||
|
||||
BehaviorEvent[] events = runtime.DrainEvents().ToArray();
|
||||
Assert.That(first.Success, Is.True);
|
||||
Assert.That(second.Success, Is.False);
|
||||
Assert.That(second.Error, Is.EqualTo("actor already has active behavior"));
|
||||
Assert.That(events.Any(e => e.Kind == BehaviorEventKind.BehaviorStopped), Is.False);
|
||||
Assert.That(events.Any(e => e.Kind == BehaviorEventKind.BehaviorStarted), Is.False);
|
||||
Assert.That(events.Any(e => e.Kind == BehaviorEventKind.TimelineAnimation), 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);
|
||||
|
||||
@@ -2,7 +2,9 @@ using NUnit.Framework;
|
||||
using System.Reflection;
|
||||
using UnityEngine;
|
||||
using XGame;
|
||||
using XGame.ActorBehavior;
|
||||
using XGame.VirtualInput;
|
||||
using XWorld.Framework.ActorBehavior;
|
||||
|
||||
public sealed class LobbyWorldControllerVirtualJoystickTests
|
||||
{
|
||||
@@ -60,6 +62,59 @@ public sealed class LobbyWorldControllerVirtualJoystickTests
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetMoveDirection_IgnoresJoystickWhileSelfBehaviorIsActive()
|
||||
{
|
||||
GameObject controllerObj = new GameObject("LobbyWorldControllerTest");
|
||||
try
|
||||
{
|
||||
LobbyWorldController controller = controllerObj.AddComponent<LobbyWorldController>();
|
||||
LobbyActorBehaviorRuntime runtime = CreateActiveSkillRuntime(10);
|
||||
|
||||
SetPrivateField(controller, "selfPlayerId", 10);
|
||||
SetPrivateField(controller, "actorBehaviorRuntime", runtime);
|
||||
SetPrivateField(controller, "joystick", Vector2.up);
|
||||
SetPrivateField(controller, "joystickActive", true);
|
||||
|
||||
Vector3 dir = (Vector3)InvokePrivate(controller, "GetMoveDirection");
|
||||
|
||||
Assert.That(dir, Is.EqualTo(Vector3.zero));
|
||||
}
|
||||
finally
|
||||
{
|
||||
Object.DestroyImmediate(controllerObj);
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Skill1TapBeforeCatalogReady_StartsAfterCatalogBecomesReady()
|
||||
{
|
||||
GameObject controllerObj = new GameObject("LobbyWorldControllerTest");
|
||||
try
|
||||
{
|
||||
LobbyWorldController controller = controllerObj.AddComponent<LobbyWorldController>();
|
||||
LobbyActorBehaviorRuntime runtime = CreateReadySkillRuntime(10);
|
||||
|
||||
SetPrivateField(controller, "selfPlayerId", 10);
|
||||
SetPrivateField(controller, "actorBehaviorRuntime", runtime);
|
||||
SetPrivateField(controller, "actorBehaviorCatalogLoaded", false);
|
||||
|
||||
InvokePrivate(controller, "OnVirtualActionButtonEvent",
|
||||
new ActionButtonEvent(ActionButtonId.Skill1, ActionButtonPhase.Tap, Vector2.zero, Vector2.zero, Vector2.zero, 0f, 0f, false, 1));
|
||||
|
||||
Assert.That(runtime.HasActiveBehavior(10), Is.False);
|
||||
|
||||
SetPrivateField(controller, "actorBehaviorCatalogLoaded", true);
|
||||
InvokePrivate(controller, "ConsumePendingActionButtonEvent");
|
||||
|
||||
Assert.That(runtime.HasActiveBehavior(10), Is.True);
|
||||
}
|
||||
finally
|
||||
{
|
||||
Object.DestroyImmediate(controllerObj);
|
||||
}
|
||||
}
|
||||
|
||||
private static void SetPrivateField(object target, string name, object value)
|
||||
{
|
||||
FieldInfo field = target.GetType().GetField(name, BindingFlags.Instance | BindingFlags.NonPublic);
|
||||
@@ -74,10 +129,55 @@ public sealed class LobbyWorldControllerVirtualJoystickTests
|
||||
return field.GetValue(target);
|
||||
}
|
||||
|
||||
private static void InvokePrivate(object target, string name, params object[] args)
|
||||
private static object InvokePrivate(object target, string name, params object[] args)
|
||||
{
|
||||
MethodInfo method = target.GetType().GetMethod(name, BindingFlags.Instance | BindingFlags.NonPublic);
|
||||
Assert.That(method, Is.Not.Null);
|
||||
method.Invoke(target, args);
|
||||
return method.Invoke(target, args);
|
||||
}
|
||||
|
||||
private static LobbyActorBehaviorRuntime CreateActiveSkillRuntime(int actorId)
|
||||
{
|
||||
LobbyActorBehaviorRuntime runtime = CreateReadySkillRuntime(actorId);
|
||||
|
||||
BehaviorStartResult result = runtime.HandleActionButton(
|
||||
new ActionButtonEvent(ActionButtonId.Skill1, ActionButtonPhase.Tap, Vector2.zero, Vector2.zero, Vector2.zero, 0f, 0f, false, 1),
|
||||
actorId,
|
||||
Vector3.forward);
|
||||
|
||||
Assert.That(result.Success, Is.True);
|
||||
Assert.That(runtime.HasActiveBehavior(actorId), Is.True);
|
||||
return runtime;
|
||||
}
|
||||
|
||||
private static LobbyActorBehaviorRuntime CreateReadySkillRuntime(int actorId)
|
||||
{
|
||||
var runtime = new LobbyActorBehaviorRuntime();
|
||||
runtime.RegisterCatalog(CreateFighterCatalog());
|
||||
runtime.RegisterOrUpdateActor(actorId, Vector3.zero, Vector3.forward);
|
||||
Assert.That(runtime.SwitchActorCatalog(actorId, LobbyActorBehaviorRuntime.DefaultCatalogType), Is.True);
|
||||
return runtime;
|
||||
}
|
||||
|
||||
private static BehaviorConfigCatalog CreateFighterCatalog()
|
||||
{
|
||||
return BehaviorConfigCatalog.LoadFromJson(
|
||||
"fighter",
|
||||
@"{
|
||||
""type"": ""fighter"",
|
||||
""version"": 1,
|
||||
""behaviors"": [
|
||||
{
|
||||
""id"": ""quantao01"",
|
||||
""duration"": 1.0,
|
||||
""canBeInterrupted"": true,
|
||||
""input"": ""DirectionOrTarget"",
|
||||
""timeline"": [],
|
||||
""logicEffects"": []
|
||||
}
|
||||
]
|
||||
}",
|
||||
@"{ ""type"": ""fighter"", ""version"": 1, ""flyObjects"": [] }",
|
||||
@"{ ""type"": ""fighter"", ""version"": 1, ""buffs"": [] }");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,6 +37,18 @@ public sealed class VirtualActionButtonTests
|
||||
Assert.That(events.Last().ButtonId, Is.EqualTo(ActionButtonId.Primary));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void PointerUpInsideButtonWithoutMeaningfulDrag_EmitsTapEvenNearButtonEdge()
|
||||
{
|
||||
VirtualActionButton button = CreateButton(ActionButtonId.Skill1);
|
||||
List<ActionButtonEvent> events = Capture(button);
|
||||
|
||||
button.HandlePointerDownForTest(new Vector2(140f, 100f), 1, 0f);
|
||||
button.HandlePointerUpForTest(new Vector2(141f, 100f), 1, 0.1f);
|
||||
|
||||
Assert.That(events.Select(e => e.Phase), Is.EqualTo(new[] { ActionButtonPhase.Down, ActionButtonPhase.Tap }));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void PointerDragPastThreshold_EmitsReleaseWithDirection()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user