Skip to content

Commit 6f43eaa

Browse files
author
David Kline
authored
Merge pull request #2920 from StephenHodgson/vNEXT-FocusFixes
Fixed issue getting focused GameObject(s) when handling input event
2 parents bef0052 + 325837d commit 6f43eaa

File tree

4 files changed

+52
-94
lines changed

4 files changed

+52
-94
lines changed

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

Lines changed: 0 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -252,52 +252,6 @@ private void Update()
252252

253253
#endregion MonoBehaviour Implementation
254254

255-
#region Focus Details by EventData
256-
257-
/// <inheritdoc />
258-
public GameObject GetFocusedObject(BaseInputEventData eventData)
259-
{
260-
Debug.Assert(eventData != null);
261-
if (OverrideFocusedObject != null) { return OverrideFocusedObject; }
262-
263-
IMixedRealityPointer pointer;
264-
return TryGetPointingSource(eventData, out pointer) ? GetFocusedObject(pointer) : null;
265-
}
266-
267-
/// <inheritdoc />
268-
public bool TryGetFocusDetails(BaseInputEventData eventData, out FocusDetails focusDetails)
269-
{
270-
foreach (var pointerData in pointers)
271-
{
272-
if (pointerData.Pointer.InputSourceParent.SourceId == eventData.SourceId)
273-
{
274-
focusDetails = pointerData.Details;
275-
return true;
276-
}
277-
}
278-
279-
focusDetails = default(FocusDetails);
280-
return false;
281-
}
282-
283-
/// <inheritdoc />
284-
public bool TryGetPointingSource(BaseInputEventData eventData, out IMixedRealityPointer pointer)
285-
{
286-
foreach (var pointerData in pointers)
287-
{
288-
if (pointerData.Pointer.InputSourceParent.SourceId == eventData.SourceId)
289-
{
290-
pointer = pointerData.Pointer;
291-
return true;
292-
}
293-
}
294-
295-
pointer = null;
296-
return false;
297-
}
298-
299-
#endregion Focus Details by EventData
300-
301255
#region Focus Details by IMixedRealityPointer
302256

303257
/// <inheritdoc />

Assets/MixedRealityToolkit-SDK/Features/Input/Handlers/DragAndDropHandler.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ void IMixedRealityPointerHandler.OnPointerDown(MixedRealityPointerEventData even
135135
currentPointer = eventData.Pointer;
136136

137137
FocusDetails focusDetails;
138-
Vector3 initialDraggingPosition = MixedRealityManager.InputSystem.FocusProvider.TryGetFocusDetails(eventData, out focusDetails)
138+
Vector3 initialDraggingPosition = MixedRealityManager.InputSystem.FocusProvider.TryGetFocusDetails(currentPointer, out focusDetails)
139139
? focusDetails.Point
140140
: hostTransform.position;
141141

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

Lines changed: 50 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -259,50 +259,77 @@ public override void HandleEvent<T>(BaseEventData eventData, ExecuteEvents.Event
259259
Debug.Assert(eventData != null);
260260
var baseInputEventData = ExecuteEvents.ValidateEventData<BaseInputEventData>(eventData);
261261
Debug.Assert(baseInputEventData != null);
262-
Debug.Assert(baseInputEventData.InputSource != null, $"Failed to find an input source for {baseInputEventData}");
263262
Debug.Assert(!baseInputEventData.used);
264263

264+
if (baseInputEventData.InputSource == null)
265+
{
266+
Debug.LogError($"Failed to find an input source for {baseInputEventData}");
267+
return;
268+
}
269+
265270
// Send the event to global listeners
266271
base.HandleEvent(eventData, eventHandler);
267272

268273
if (baseInputEventData.used)
269274
{
270-
// All global listeners get a chance to see the event, but if any of them marked it used, we stop
271-
// the event from going any further.
275+
// All global listeners get a chance to see the event,
276+
// but if any of them marked it used,
277+
// we stop the event from going any further.
278+
return;
279+
}
280+
281+
if (baseInputEventData.InputSource.Pointers == null)
282+
{
283+
Debug.LogError($"InputSource {baseInputEventData.InputSource.SourceName} doesn't have any registered pointers! Input Sources without pointers should use the GazeProvider's pointer as a default fallback.");
272284
return;
273285
}
274286

275-
GameObject focusedObject = FocusProvider?.GetFocusedObject(baseInputEventData);
287+
var modalEventHandled = false;
276288

277-
// Handle modal input if one exists
278-
if (modalInputStack.Count > 0)
289+
// Get the focused object for each pointer of the event source
290+
for (int i = 0; i < baseInputEventData.InputSource.Pointers.Length; i++)
279291
{
280-
GameObject modalInput = modalInputStack.Peek();
292+
GameObject focusedObject = FocusProvider?.GetFocusedObject(baseInputEventData.InputSource.Pointers[i]);
281293

282-
// If there is a focused object in the hierarchy of the modal handler, start the event bubble there
283-
if (focusedObject != null && modalInput != null && focusedObject.transform.IsChildOf(modalInput.transform))
294+
// Handle modal input if one exists
295+
if (modalInputStack.Count > 0 && !modalEventHandled)
284296
{
285-
if (ExecuteEvents.ExecuteHierarchy(focusedObject, baseInputEventData, eventHandler) && baseInputEventData.used)
297+
GameObject modalInput = modalInputStack.Peek();
298+
299+
if (modalInput != null)
286300
{
287-
return;
301+
modalEventHandled = true;
302+
303+
// If there is a focused object in the hierarchy of the modal handler, start the event bubble there
304+
if (focusedObject != null && focusedObject.transform.IsChildOf(modalInput.transform))
305+
{
306+
if (ExecuteEvents.ExecuteHierarchy(focusedObject, baseInputEventData, eventHandler) && baseInputEventData.used)
307+
{
308+
return;
309+
}
310+
}
311+
// Otherwise, just invoke the event on the modal handler itself
312+
else
313+
{
314+
if (ExecuteEvents.ExecuteHierarchy(modalInput, baseInputEventData, eventHandler) && baseInputEventData.used)
315+
{
316+
return;
317+
}
318+
}
288319
}
289-
}
290-
// Otherwise, just invoke the event on the modal handler itself
291-
else
292-
{
293-
if (ExecuteEvents.ExecuteHierarchy(modalInput, baseInputEventData, eventHandler) && baseInputEventData.used)
320+
else
294321
{
295-
return;
322+
Debug.LogError("ModalInput GameObject reference was null!\nDid this GameObject get destroyed?");
296323
}
297324
}
298-
}
299325

300-
// If event was not handled by modal, pass it on to the current focused object
301-
if (focusedObject != null)
302-
{
303-
if (ExecuteEvents.ExecuteHierarchy(focusedObject, baseInputEventData, eventHandler) && baseInputEventData.used)
326+
// If event was not handled by modal, pass it on to the current focused object
327+
if (focusedObject != null)
304328
{
305-
return;
329+
if (ExecuteEvents.ExecuteHierarchy(focusedObject, baseInputEventData, eventHandler) && baseInputEventData.used)
330+
{
331+
return;
332+
}
306333
}
307334
}
308335

Assets/MixedRealityToolkit/_Core/Interfaces/InputSystem/IMixedRealityFocusProvider.cs

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -31,29 +31,6 @@ public interface IMixedRealityFocusProvider : IMixedRealitySourceStateHandler
3131
/// </summary>
3232
GameObject OverrideFocusedObject { get; set; }
3333

34-
/// <summary>
35-
/// Gets the currently focused object based on specified the event data.
36-
/// </summary>
37-
/// <param name="eventData"></param>
38-
/// <returns>Currently focused <see cref="GameObject"/> for the events input source.</returns>
39-
GameObject GetFocusedObject(BaseInputEventData eventData);
40-
41-
/// <summary>
42-
/// Try to get the focus details based on the specified event data.
43-
/// </summary>
44-
/// <param name="eventData"></param>
45-
/// <param name="focusDetails"></param>
46-
/// <returns>True, if event data pointer input source is registered.</returns>
47-
bool TryGetFocusDetails(BaseInputEventData eventData, out FocusDetails focusDetails);
48-
49-
/// <summary>
50-
/// Try to get the registered pointer source that raised the event.
51-
/// </summary>
52-
/// <param name="eventData"></param>
53-
/// <param name="pointer"></param>
54-
/// <returns>True, if event data's pointer input source is registered.</returns>
55-
bool TryGetPointingSource(BaseInputEventData eventData, out IMixedRealityPointer pointer);
56-
5734
/// <summary>
5835
/// Gets the currently focused object for the pointing source.
5936
/// <para><remarks>If the pointing source is not registered, then the Gaze's Focused <see cref="GameObject"/> is returned.</remarks></para>
@@ -73,7 +50,7 @@ public interface IMixedRealityFocusProvider : IMixedRealitySourceStateHandler
7350
/// Get the Graphic Event Data for the specified pointing source.
7451
/// </summary>
7552
/// <param name="pointer">The pointer who's graphic event data we're looking for.</param>
76-
/// <param name="graphicInputEventData">The graphihc event data for the specified pointer</param>
53+
/// <param name="graphicInputEventData">The graphic event data for the specified pointer</param>
7754
/// <returns>True, if graphic event data exists.</returns>
7855
bool TryGetSpecificPointerGraphicEventData(IMixedRealityPointer pointer, out GraphicInputEventData graphicInputEventData);
7956

0 commit comments

Comments
 (0)