public void Actions_CanCustomizeButtonPressPointsOfInteractions() { var gamepad = InputSystem.AddDevice <Gamepad>(); var pressAction = new InputAction("PressAction", binding: "<Gamepad>/leftTrigger", interactions: "press(pressPoint=0.234)"); var tapAction = new InputAction("TapAction", binding: "<Gamepad>/leftTrigger", interactions: "tap(pressPoint=0.345)"); var slowTapAction = new InputAction("SlowTapAction", binding: "<Gamepad>/leftTrigger", interactions: "slowtap(pressPoint=0.456)"); var multiTapAction = new InputAction("MultiTapAction", binding: "<Gamepad>/leftTrigger", interactions: "multitap(pressPoint=0.567)"); var holdAction = new InputAction("HoldAction", binding: "<Gamepad>/leftTrigger", interactions: "hold(pressPoint=0.678)"); pressAction.Enable(); tapAction.Enable(); slowTapAction.Enable(); multiTapAction.Enable(); holdAction.Enable(); // Render the global default inactive. InputSystem.settings.defaultButtonPressPoint = 0; using (var trace = new InputActionTrace()) { trace.SubscribeToAll(); Set(gamepad.leftTrigger, 0.123f); Assert.That(trace, Started <PressInteraction>(pressAction)); trace.Clear(); Set(gamepad.leftTrigger, 0.3f); Assert.That(trace, Performed <PressInteraction>(pressAction)); trace.Clear(); Set(gamepad.leftTrigger, 0.4f); Assert.That(trace, Started <TapInteraction>(tapAction)); trace.Clear(); Set(gamepad.leftTrigger, 0.5f); Assert.That(trace, Started <SlowTapInteraction>(slowTapAction)); trace.Clear(); Set(gamepad.leftTrigger, 0.6f); Assert.That(trace, Started <MultiTapInteraction>(multiTapAction)); trace.Clear(); Set(gamepad.leftTrigger, 0.7f); Assert.That(trace, Started <HoldInteraction>(holdAction)); } }
public void Actions_CanPerformPressInteraction() { var gamepad = InputSystem.AddDevice <Gamepad>(); // We add a second input device (and bind to it), to test that the binding // conflict resolution will not interfere with the interaction handling. InputSystem.AddDevice <Keyboard>(); // Test all three press behaviors concurrently. var pressOnlyAction = new InputAction("PressOnly", binding: "<Gamepad>/buttonSouth", interactions: "press"); pressOnlyAction.AddBinding("<Keyboard>/a"); var releaseOnlyAction = new InputAction("ReleaseOnly", binding: "<Gamepad>/buttonSouth", interactions: "press(behavior=1)"); releaseOnlyAction.AddBinding("<Keyboard>/s"); var pressAndReleaseAction = new InputAction("PressAndRelease", binding: "<Gamepad>/buttonSouth", interactions: "press(behavior=2)"); pressAndReleaseAction.AddBinding("<Keyboard>/d"); pressOnlyAction.Enable(); releaseOnlyAction.Enable(); pressAndReleaseAction.Enable(); using (var trace = new InputActionTrace()) { trace.SubscribeToAll(); runtime.currentTime = 1; Press(gamepad.buttonSouth); var actions = trace.ToArray(); Assert.That(actions, Has.Length.EqualTo(5)); Assert.That(actions, Has.Exactly(1).With.Property("action").SameAs(pressOnlyAction).And.With.Property("phase") .EqualTo(InputActionPhase.Started).And.With.Property("duration") .EqualTo(0)); Assert.That(actions, Has.Exactly(1).With.Property("action").SameAs(pressOnlyAction).And.With.Property("phase") .EqualTo(InputActionPhase.Performed).And.With.Property("duration") .EqualTo(0)); Assert.That(actions, Has.Exactly(1).With.Property("action").SameAs(pressAndReleaseAction).And.With.Property("phase") .EqualTo(InputActionPhase.Started).And.With.Property("duration") .EqualTo(0)); Assert.That(actions, Has.Exactly(1).With.Property("action").SameAs(pressAndReleaseAction).And.With.Property("phase") .EqualTo(InputActionPhase.Performed).And.With.Property("duration") .EqualTo(0)); Assert.That(actions, Has.Exactly(1).With.Property("action").SameAs(releaseOnlyAction).And.With.Property("phase") .EqualTo(InputActionPhase.Started).And.With.Property("duration") .EqualTo(0)); trace.Clear(); runtime.currentTime = 2; Release(gamepad.buttonSouth); actions = trace.ToArray(); Assert.That(actions, Has.Length.EqualTo(3)); Assert.That(actions, Has.Exactly(1).With.Property("action").SameAs(releaseOnlyAction).And.With.Property("phase") .EqualTo(InputActionPhase.Performed).And.With.Property("duration") .EqualTo(1)); Assert.That(actions, Has.Exactly(1).With.Property("action").SameAs(pressAndReleaseAction).And.With.Property("phase") .EqualTo(InputActionPhase.Started).And.With.Property("duration") .EqualTo(0)); Assert.That(actions, Has.Exactly(1).With.Property("action").SameAs(pressAndReleaseAction).And.With.Property("phase") .EqualTo(InputActionPhase.Performed).And.With.Property("duration") .EqualTo(0)); trace.Clear(); runtime.currentTime = 5; Press(gamepad.buttonSouth); actions = trace.ToArray(); Assert.That(actions, Has.Length.EqualTo(5)); Assert.That(actions, Has.Exactly(1).With.Property("action").SameAs(pressOnlyAction).And.With.Property("phase") .EqualTo(InputActionPhase.Started).And.With.Property("duration") .EqualTo(0)); Assert.That(actions, Has.Exactly(1).With.Property("action").SameAs(pressOnlyAction).And.With.Property("phase") .EqualTo(InputActionPhase.Performed).And.With.Property("duration") .EqualTo(0)); Assert.That(actions, Has.Exactly(1).With.Property("action").SameAs(pressAndReleaseAction).And.With.Property("phase") .EqualTo(InputActionPhase.Started).And.With.Property("duration") .EqualTo(0)); Assert.That(actions, Has.Exactly(1).With.Property("action").SameAs(pressAndReleaseAction).And.With.Property("phase") .EqualTo(InputActionPhase.Performed).And.With.Property("duration") .EqualTo(0)); Assert.That(actions, Has.Exactly(1).With.Property("action").SameAs(releaseOnlyAction).And.With.Property("phase") .EqualTo(InputActionPhase.Started).And.With.Property("duration") .EqualTo(0)); } }
public void StartedValidSweepBehavior(SectorInteraction.SweepBehavior sweepBehavior) { var gamepad = InputSystem.InputSystem.AddDevice <Gamepad>(); var action = new InputAction( type: InputActionType.Value, binding: "<Gamepad>/rightStick", interactions: CreateInteractionString(SectorInteraction.Directions.North, sweepBehavior)); action.Enable(); var north = new Vector2(0f, 1f); var east = new Vector2(1f, 0f); var center = Vector2.zero; // Starting below threshold Assert.That(gamepad.rightStick.IsActuated(), Is.False); Assert.That(action.triggered, Is.False); using (var trace = new InputActionTrace()) { trace.SubscribeToAll(); // Actuate above threshold, in valid sector Set(gamepad.rightStick, north); Assert.That(gamepad.rightStick.IsActuated(), Is.True); Assert.That(trace, Started <SectorInteraction>(action).AndThen(Performed <SectorInteraction>(action))); Assert.That(action.triggered, Is.True); trace.Clear(); // Sweep to invalid sector Set(gamepad.rightStick, east); Assert.That(gamepad.rightStick.IsActuated(), Is.True); switch (sweepBehavior) { case SectorInteraction.SweepBehavior.Locked: Assert.That(trace, Is.Empty); break; case SectorInteraction.SweepBehavior.AllowReentry: case SectorInteraction.SweepBehavior.DisallowReentry: case SectorInteraction.SweepBehavior.HistoryIndependent: Assert.That(trace, Canceled <SectorInteraction>(action)); break; default: Assert.Fail($"Unhandled {nameof(SectorInteraction.SweepBehavior)}={sweepBehavior}"); return; } Assert.That(action.triggered, Is.False); trace.Clear(); // Sweep back into valid sector Set(gamepad.rightStick, north); Assert.That(gamepad.rightStick.IsActuated(), Is.True); switch (sweepBehavior) { case SectorInteraction.SweepBehavior.Locked: case SectorInteraction.SweepBehavior.DisallowReentry: Assert.That(trace, Is.Empty); Assert.That(action.triggered, Is.False); break; case SectorInteraction.SweepBehavior.AllowReentry: case SectorInteraction.SweepBehavior.HistoryIndependent: Assert.That(trace, Started <SectorInteraction>(action).AndThen(Performed <SectorInteraction>(action))); Assert.That(action.triggered, Is.True); break; default: Assert.Fail($"Unhandled {nameof(SectorInteraction.SweepBehavior)}={sweepBehavior}"); return; } trace.Clear(); // Return to center, under threshold Set(gamepad.rightStick, center); Assert.That(gamepad.rightStick.IsActuated(), Is.False); Assert.That(trace, Canceled <SectorInteraction>(action)); Assert.That(action.triggered, Is.False); } }