@@ -10041,6 +10041,112 @@ public void Actions_CanCreateCompositesWithMultipleBindings()
1004110041 Assert.That(value, Is.EqualTo(new Vector2(-1, -1).normalized).Using(Vector2EqualityComparer.Instance));
1004210042 }
1004310043
10044+ // Ensure that https://jira.unity3d.com/browse/ISXB-619 regress
10045+ [Test]
10046+ [Category("Actions")]
10047+ public void Actions_WithCompositeWithMultipleInteractions_Works()
10048+ {
10049+ // Will ensure that :
10050+ // PressRelease AW trigger a tap
10051+ // Long PressRelease AW trigger a hold
10052+ // PressRelease AW trigger a tap
10053+
10054+ var keyboard = InputSystem.AddDevice<Keyboard>();
10055+ var action = new InputAction();
10056+ action.AddCompositeBinding("Dpad", interactions: "tap,hold(duration=2)")
10057+ .With("Up", "<Keyboard>/w")
10058+ .With("Down", "<Keyboard>/s")
10059+ .With("Left", "<Keyboard>/a")
10060+ .With("Right", "<Keyboard>/d");
10061+ action.Enable();
10062+
10063+ IInputInteraction performedInteraction = null;
10064+ IInputInteraction canceledInteraction = null;
10065+ action.performed += ctx =>
10066+ {
10067+ performedInteraction = ctx.interaction;
10068+ };
10069+ action.canceled += ctx =>
10070+ {
10071+ canceledInteraction = ctx.interaction;
10072+ };
10073+
10074+ // PressRelease AW trigger a tap
10075+ currentTime = 0;
10076+ InputSystem.QueueStateEvent(keyboard, new KeyboardState(Key.A, Key.W));
10077+ InputSystem.Update();
10078+
10079+ // nothing triggered
10080+ Assert.That(canceledInteraction, Is.Null);
10081+ Assert.That(performedInteraction, Is.Null);
10082+
10083+ currentTime += InputSystem.settings.defaultTapTime / 2.0f; // half of the tap time to ensure that it performs.
10084+ InputSystem.QueueStateEvent(keyboard, new KeyboardState());
10085+ InputSystem.Update();
10086+
10087+ // tap should be triggered
10088+ Assert.That(canceledInteraction, Is.Null);
10089+ Assert.That(performedInteraction, Is.TypeOf(typeof(TapInteraction)));
10090+ performedInteraction = null;
10091+
10092+ // Long PressRelease AW trigger a hold
10093+ currentTime += 1;
10094+ InputSystem.QueueStateEvent(keyboard, new KeyboardState(Key.A, Key.W));
10095+ InputSystem.Update();
10096+
10097+ // tap should be canceled
10098+ currentTime += InputSystem.settings.defaultTapTime * 4.0;
10099+ InputSystem.Update();
10100+
10101+ Assert.That(canceledInteraction, Is.TypeOf(typeof(TapInteraction)));
10102+ Assert.That(performedInteraction, Is.Null);
10103+ canceledInteraction = null;
10104+
10105+ // After (defaultTapTime*4 + 2) seconds hold should be performed with duration=2
10106+ currentTime += 2;
10107+ InputSystem.Update();
10108+ Assert.That(canceledInteraction, Is.Null);
10109+ Assert.That(performedInteraction, Is.TypeOf(typeof(HoldInteraction)));
10110+ performedInteraction = null;
10111+
10112+ // hold should be canceled
10113+ currentTime += 1;
10114+ InputSystem.QueueStateEvent(keyboard, new KeyboardState());
10115+ InputSystem.Update();
10116+ Assert.That(canceledInteraction, Is.TypeOf(typeof(HoldInteraction)));
10117+ Assert.That(performedInteraction, Is.Null);
10118+ canceledInteraction = null;
10119+
10120+ // Should be no other remaining events
10121+ currentTime += 5;
10122+ InputSystem.Update();
10123+ Assert.That(canceledInteraction, Is.Null);
10124+ Assert.That(performedInteraction, Is.Null);
10125+
10126+ // PressRelease AW trigger a tap to ensure that is still working
10127+ currentTime += 1;
10128+ InputSystem.QueueStateEvent(keyboard, new KeyboardState(Key.A, Key.W));
10129+ InputSystem.Update();
10130+
10131+ Assert.That(canceledInteraction, Is.Null);
10132+ Assert.That(performedInteraction, Is.Null);
10133+
10134+ currentTime += InputSystem.settings.defaultTapTime / 2.0f;
10135+ InputSystem.QueueStateEvent(keyboard, new KeyboardState());
10136+ InputSystem.Update();
10137+
10138+ Assert.That(canceledInteraction, Is.Null);
10139+ Assert.That(performedInteraction, Is.TypeOf(typeof(TapInteraction)));
10140+ performedInteraction = null;
10141+ canceledInteraction = null;
10142+
10143+ // Should be no other remaining events
10144+ currentTime += 100;
10145+ InputSystem.Update();
10146+ Assert.That(canceledInteraction, Is.Null);
10147+ Assert.That(performedInteraction, Is.Null);
10148+ }
10149+
1004410150 [Test]
1004510151 [Category("Actions")]
1004610152 public void Actions_WithMultipleComposites_CancelsIfCompositeIsReleased()
0 commit comments