@@ -9610,6 +9610,165 @@ public void Actions_Vector2Composite_WithKeyboardKeys_CancelOnRelease()
96109610 }
96119611 }
96129612
9613+ [Test]
9614+ [Category("Actions")]
9615+ public void Actions_CanCreateComposite_WithMultipleBindingsPerPart()
9616+ {
9617+ var keyboard = InputSystem.AddDevice<Keyboard>();
9618+
9619+ // Set up classic WASD control and additional arrow key support on the same composite.
9620+ var action = new InputAction();
9621+ action.AddCompositeBinding("Dpad")
9622+ .With("Up", "<Keyboard>/w")
9623+ .With("Down", "<Keyboard>/s")
9624+ .With("Left", "<Keyboard>/a")
9625+ .With("Right", "<Keyboard>/d")
9626+ .With("Up", "<Keyboard>/upArrow")
9627+ .With("Down", "<Keyboard>/downArrow")
9628+ .With("Left", "<Keyboard>/leftArrow")
9629+ .With("Right", "<Keyboard>/rightArrow");
9630+ action.Enable();
9631+
9632+ Vector2? value = null;
9633+ action.performed += ctx => { value = ctx.ReadValue<Vector2>(); };
9634+
9635+ // Up.
9636+ value = null;
9637+ InputSystem.QueueStateEvent(keyboard, new KeyboardState(Key.W));
9638+ InputSystem.Update();
9639+
9640+ Assert.That(value, Is.Not.Null);
9641+ Assert.That(value.Value, Is.EqualTo(Vector2.up));
9642+
9643+ // Up left.
9644+ value = null;
9645+ InputSystem.QueueStateEvent(keyboard, new KeyboardState(Key.W, Key.A));
9646+ InputSystem.Update();
9647+
9648+ Assert.That(value, Is.Not.Null);
9649+ Assert.That(value.Value.x, Is.EqualTo((Vector2.up + Vector2.left).normalized.x).Within(0.00001));
9650+ Assert.That(value.Value.y, Is.EqualTo((Vector2.up + Vector2.left).normalized.y).Within(0.00001));
9651+
9652+ // Left.
9653+ value = null;
9654+ InputSystem.QueueStateEvent(keyboard, new KeyboardState(Key.A));
9655+ InputSystem.Update();
9656+
9657+ Assert.That(value, Is.Not.Null);
9658+ Assert.That(value.Value, Is.EqualTo(Vector2.left));
9659+
9660+ // Down left.
9661+ value = null;
9662+ InputSystem.QueueStateEvent(keyboard, new KeyboardState(Key.A, Key.S));
9663+ InputSystem.Update();
9664+
9665+ Assert.That(value, Is.Not.Null);
9666+ Assert.That(value.Value.x, Is.EqualTo((Vector2.left + Vector2.down).normalized.x).Within(0.00001));
9667+ Assert.That(value.Value.y, Is.EqualTo((Vector2.left + Vector2.down).normalized.y).Within(0.00001));
9668+
9669+ // Down.
9670+ value = null;
9671+ InputSystem.QueueStateEvent(keyboard, new KeyboardState(Key.S));
9672+ InputSystem.Update();
9673+
9674+ Assert.That(value, Is.Not.Null);
9675+ Assert.That(value.Value, Is.EqualTo(Vector2.down));
9676+
9677+ // Down right.
9678+ value = null;
9679+ InputSystem.QueueStateEvent(keyboard, new KeyboardState(Key.S, Key.D));
9680+ InputSystem.Update();
9681+
9682+ Assert.That(value, Is.Not.Null);
9683+ Assert.That(value.Value.x, Is.EqualTo((Vector2.down + Vector2.right).normalized.x).Within(0.00001));
9684+ Assert.That(value.Value.y, Is.EqualTo((Vector2.down + Vector2.right).normalized.y).Within(0.00001));
9685+
9686+ // Right.
9687+ value = null;
9688+ InputSystem.QueueStateEvent(keyboard, new KeyboardState(Key.D));
9689+ InputSystem.Update();
9690+
9691+ Assert.That(value, Is.Not.Null);
9692+ Assert.That(value.Value, Is.EqualTo(Vector2.right));
9693+
9694+ // Up right.
9695+ value = null;
9696+ InputSystem.QueueStateEvent(keyboard, new KeyboardState(Key.D, Key.W));
9697+ InputSystem.Update();
9698+
9699+ Assert.That(value, Is.Not.Null);
9700+ Assert.That(value.Value.x, Is.EqualTo((Vector2.right + Vector2.up).normalized.x).Within(0.00001));
9701+ Assert.That(value.Value.y, Is.EqualTo((Vector2.right + Vector2.up).normalized.y).Within(0.00001));
9702+
9703+ // Up.
9704+ value = null;
9705+ InputSystem.QueueStateEvent(keyboard, new KeyboardState(Key.UpArrow));
9706+ InputSystem.Update();
9707+
9708+ Assert.That(value, Is.Not.Null);
9709+ Assert.That(value.Value, Is.EqualTo(Vector2.up));
9710+
9711+ // Up left.
9712+ value = null;
9713+ InputSystem.QueueStateEvent(keyboard, new KeyboardState(Key.UpArrow, Key.LeftArrow));
9714+ InputSystem.Update();
9715+
9716+ Assert.That(value, Is.Not.Null);
9717+ Assert.That(value.Value.x, Is.EqualTo((Vector2.up + Vector2.left).normalized.x).Within(0.00001));
9718+ Assert.That(value.Value.y, Is.EqualTo((Vector2.up + Vector2.left).normalized.y).Within(0.00001));
9719+
9720+ // Left.
9721+ value = null;
9722+ InputSystem.QueueStateEvent(keyboard, new KeyboardState(Key.LeftArrow));
9723+ InputSystem.Update();
9724+
9725+ Assert.That(value, Is.Not.Null);
9726+ Assert.That(value.Value, Is.EqualTo(Vector2.left));
9727+
9728+ // Down left.
9729+ value = null;
9730+ InputSystem.QueueStateEvent(keyboard, new KeyboardState(Key.LeftArrow, Key.DownArrow));
9731+ InputSystem.Update();
9732+
9733+ Assert.That(value, Is.Not.Null);
9734+ Assert.That(value.Value.x, Is.EqualTo((Vector2.left + Vector2.down).normalized.x).Within(0.00001));
9735+ Assert.That(value.Value.y, Is.EqualTo((Vector2.left + Vector2.down).normalized.y).Within(0.00001));
9736+
9737+ // Down.
9738+ value = null;
9739+ InputSystem.QueueStateEvent(keyboard, new KeyboardState(Key.DownArrow));
9740+ InputSystem.Update();
9741+
9742+ Assert.That(value, Is.Not.Null);
9743+ Assert.That(value.Value, Is.EqualTo(Vector2.down));
9744+
9745+ // Down right.
9746+ value = null;
9747+ InputSystem.QueueStateEvent(keyboard, new KeyboardState(Key.DownArrow, Key.RightArrow));
9748+ InputSystem.Update();
9749+
9750+ Assert.That(value, Is.Not.Null);
9751+ Assert.That(value.Value.x, Is.EqualTo((Vector2.down + Vector2.right).normalized.x).Within(0.00001));
9752+ Assert.That(value.Value.y, Is.EqualTo((Vector2.down + Vector2.right).normalized.y).Within(0.00001));
9753+
9754+ // Right.
9755+ value = null;
9756+ InputSystem.QueueStateEvent(keyboard, new KeyboardState(Key.RightArrow));
9757+ InputSystem.Update();
9758+
9759+ Assert.That(value, Is.Not.Null);
9760+ Assert.That(value.Value, Is.EqualTo(Vector2.right));
9761+
9762+ // Up right.
9763+ value = null;
9764+ InputSystem.QueueStateEvent(keyboard, new KeyboardState(Key.RightArrow, Key.UpArrow));
9765+ InputSystem.Update();
9766+
9767+ Assert.That(value, Is.Not.Null);
9768+ Assert.That(value.Value.x, Is.EqualTo((Vector2.right + Vector2.up).normalized.x).Within(0.00001));
9769+ Assert.That(value.Value.y, Is.EqualTo((Vector2.right + Vector2.up).normalized.y).Within(0.00001));
9770+ }
9771+
96139772 [Test]
96149773 [Category("Actions")]
96159774 public void Actions_CanCreateComposite_WithPartsBeingOutOfOrder()
0 commit comments