Skip to content

Commit d7f523d

Browse files
Updated ModalInput to only fire once
1 parent 409a8aa commit d7f523d

File tree

1 file changed

+23
-12
lines changed

1 file changed

+23
-12
lines changed

Assets/MixedRealityToolkit-SDK/Features/Input/MixedRealityInputManager.cs

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -275,8 +275,9 @@ public override void HandleEvent<T>(BaseEventData eventData, ExecuteEvents.Event
275275

276276
if (baseInputEventData.used)
277277
{
278-
// All global listeners get a chance to see the event, but if any of them marked it used, we stop
279-
// the event from going any further.
278+
// All global listeners get a chance to see the event,
279+
// but if any of them marked it used,
280+
// we stop the event from going any further.
280281
return;
281282
}
282283

@@ -286,31 +287,41 @@ public override void HandleEvent<T>(BaseEventData eventData, ExecuteEvents.Event
286287
return;
287288
}
288289

290+
var modalEventHandled = false;
291+
289292
// Get the focused object for each pointer of the event source
290293
for (int i = 0; i < baseInputEventData.InputSource.Pointers.Length; i++)
291294
{
292295
GameObject focusedObject = FocusProvider?.GetFocusedObject(baseInputEventData.InputSource.Pointers[i]);
293296

294297
// Handle modal input if one exists
295-
if (modalInputStack.Count > 0)
298+
if (modalInputStack.Count > 0 && !modalEventHandled)
296299
{
297300
GameObject modalInput = modalInputStack.Peek();
298301

299-
// If there is a focused object in the hierarchy of the modal handler, start the event bubble there
300-
if (focusedObject != null && modalInput != null && focusedObject.transform.IsChildOf(modalInput.transform))
302+
if (modalInput != null)
301303
{
302-
if (ExecuteEvents.ExecuteHierarchy(focusedObject, baseInputEventData, eventHandler) && baseInputEventData.used)
304+
modalEventHandled = true;
305+
// If there is a focused object in the hierarchy of the modal handler, start the event bubble there
306+
if (focusedObject != null && focusedObject.transform.IsChildOf(modalInput.transform))
307+
{
308+
if (ExecuteEvents.ExecuteHierarchy(focusedObject, baseInputEventData, eventHandler) && baseInputEventData.used)
309+
{
310+
return;
311+
}
312+
}
313+
// Otherwise, just invoke the event on the modal handler itself
314+
else
303315
{
304-
return;
316+
if (ExecuteEvents.ExecuteHierarchy(modalInput, baseInputEventData, eventHandler) && baseInputEventData.used)
317+
{
318+
return;
319+
}
305320
}
306321
}
307-
// Otherwise, just invoke the event on the modal handler itself
308322
else
309323
{
310-
if (ExecuteEvents.ExecuteHierarchy(modalInput, baseInputEventData, eventHandler) && baseInputEventData.used)
311-
{
312-
return;
313-
}
324+
Debug.LogError("ModalInput GameObject reference was null!\nDid this GameObject get destroyed?");
314325
}
315326
}
316327

0 commit comments

Comments
 (0)