@@ -58,6 +58,113 @@ public void Settings_ShouldStoreSettingsAndFeatureFlags(string featureName)
5858 }
5959 }
6060
61+ [Test]
62+ [Category("Actions")]
63+ public void Actions_WithMultipleBindingsAndMultipleInteractions_Works()
64+ {
65+ InputSystem.settings.defaultButtonPressPoint = 0.5f;
66+
67+ var keyboard = InputSystem.AddDevice<Keyboard>();
68+
69+ var action = new InputAction(interactions: "tap,hold(duration=2)");
70+ action.AddBinding("<Keyboard>/w");
71+ action.AddBinding("<Keyboard>/a");
72+ action.Enable();
73+
74+ IInputInteraction performedInteraction = null;
75+ IInputInteraction canceledInteraction = null;
76+ action.performed += ctx =>
77+ {
78+ performedInteraction = ctx.interaction;
79+ };
80+ action.canceled += ctx =>
81+ {
82+ canceledInteraction = ctx.interaction;
83+ };
84+
85+ // PressRelease AW trigger a tap
86+ currentTime = 0;
87+ InputSystem.QueueStateEvent(keyboard, new KeyboardState(Key.A, Key.W));
88+ InputSystem.Update();
89+
90+ // nothing triggered
91+ Assert.That(canceledInteraction, Is.Null);
92+ Assert.That(performedInteraction, Is.Null);
93+
94+ currentTime = 0.01;
95+ InputSystem.QueueStateEvent(keyboard, new KeyboardState());
96+ InputSystem.Update();
97+
98+ // tap should be triggered
99+ Assert.That(canceledInteraction, Is.Null);
100+ Assert.That(performedInteraction, Is.TypeOf(typeof(TapInteraction)));
101+ performedInteraction = null;
102+
103+ // Should be no other remaining events
104+ currentTime = 10;
105+ InputSystem.Update();
106+ Assert.That(canceledInteraction, Is.Null);
107+ Assert.That(performedInteraction, Is.Null);
108+
109+
110+
111+ // PressRelease AW trigger a tap
112+ currentTime = 11;
113+ InputSystem.QueueStateEvent(keyboard, new KeyboardState(Key.A, Key.W));
114+ InputSystem.Update();
115+
116+ // nothing triggered
117+ Assert.That(canceledInteraction, Is.Null);
118+ Assert.That(performedInteraction, Is.Null);
119+
120+ currentTime = 11.01;
121+ InputSystem.QueueStateEvent(keyboard, new KeyboardState(Key.A));
122+ InputSystem.Update();
123+
124+ currentTime = 11.02;
125+ InputSystem.QueueStateEvent(keyboard, new KeyboardState());
126+ InputSystem.Update();
127+
128+ // tap should be triggered
129+ Assert.That(canceledInteraction, Is.Null);
130+ Assert.That(performedInteraction, Is.TypeOf(typeof(TapInteraction)));
131+ performedInteraction = null;
132+
133+ // Should be no other remaining events
134+ currentTime = 20;
135+ InputSystem.Update();
136+ Assert.That(canceledInteraction, Is.Null);
137+ Assert.That(performedInteraction, Is.Null);
138+
139+ // PressRelease AW trigger a tap
140+ currentTime = 21;
141+ InputSystem.QueueStateEvent(keyboard, new KeyboardState(Key.A, Key.W));
142+ InputSystem.Update();
143+
144+ // nothing triggered
145+ Assert.That(canceledInteraction, Is.Null);
146+ Assert.That(performedInteraction, Is.Null);
147+
148+ currentTime = 21.01;
149+ InputSystem.QueueStateEvent(keyboard, new KeyboardState(Key.W));
150+ InputSystem.Update();
151+
152+ currentTime = 21.02;
153+ InputSystem.QueueStateEvent(keyboard, new KeyboardState());
154+ InputSystem.Update();
155+
156+ // tap should be triggered
157+ Assert.That(canceledInteraction, Is.Null);
158+ Assert.That(performedInteraction, Is.TypeOf(typeof(TapInteraction)));
159+ performedInteraction = null;
160+
161+ // Should be no other remaining events
162+ currentTime = 30;
163+ InputSystem.Update();
164+ Assert.That(canceledInteraction, Is.Null);
165+ Assert.That(performedInteraction, Is.Null);
166+ }
167+
61168 [Test]
62169 [Category("Actions")]
63170 public void Actions_WhenShortcutsDisabled_AllConflictingActionsTrigger()
0 commit comments