Skip to content

Commit 4aaea3a

Browse files
reorganized focus provider a bit and moved documentation to the interface.
1 parent 105e7b0 commit 4aaea3a

File tree

4 files changed

+155
-101
lines changed

4 files changed

+155
-101
lines changed

Assets/MixedRealityToolkit/InputSystem/Focus/FocusProvider.cs

Lines changed: 62 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,43 @@ public class FocusProvider : MonoBehaviour, IMixedRealityFocusProvider
2424
private IMixedRealityInputSystem inputSystem = null;
2525
public IMixedRealityInputSystem InputSystem => inputSystem ?? (inputSystem = MixedRealityManager.Instance.GetManager<IMixedRealityInputSystem>());
2626

27-
/// <summary>
28-
/// Maximum distance at which the pointer can collide with an object.
29-
/// </summary>
27+
private readonly HashSet<PointerData> pointers = new HashSet<PointerData>();
28+
private readonly HashSet<GameObject> pendingOverallFocusEnterSet = new HashSet<GameObject>();
29+
private readonly HashSet<GameObject> pendingOverallFocusExitSet = new HashSet<GameObject>();
30+
private readonly List<PointerData> pendingPointerSpecificFocusChange = new List<PointerData>();
31+
32+
#region IFocusProvider Properties
33+
3034
[SerializeField]
35+
[Tooltip("Maximum distance at which all pointers can collide with an object, unless it has an override extent.")]
3136
private float pointingExtent = 10f;
3237

38+
/// <inheritdoc />
3339
float IMixedRealityFocusProvider.GlobalPointingExtent => pointingExtent;
3440

41+
[SerializeField]
42+
[Tooltip("Camera to use for raycasting uGUI pointer events.")]
43+
private Camera uiRaycastCamera = null;
44+
45+
/// <inheritdoc />
46+
public Camera UIRaycastCamera
47+
{
48+
get
49+
{
50+
if (uiRaycastCamera == null)
51+
{
52+
CreateUiRaycastCamera();
53+
}
54+
55+
return uiRaycastCamera;
56+
}
57+
}
58+
59+
/// <inheritdoc />
60+
public GameObject OverrideFocusedObject { get; set; }
61+
62+
#endregion IFocusProvider Properties
63+
3564
/// <summary>
3665
/// The LayerMasks, in prioritized order, that are used to determine the GazeTarget when raycasting.
3766
/// <example>
@@ -60,55 +89,31 @@ public class FocusProvider : MonoBehaviour, IMixedRealityFocusProvider
6089
/// </summary>
6190
private PointerData gazeManagerPointingData;
6291

63-
private readonly HashSet<PointerData> pointers = new HashSet<PointerData>();
64-
private readonly HashSet<GameObject> pendingOverallFocusEnterSet = new HashSet<GameObject>();
65-
private readonly HashSet<GameObject> pendingOverallFocusExitSet = new HashSet<GameObject>();
66-
private readonly List<PointerData> pendingPointerSpecificFocusChange = new List<PointerData>();
67-
6892
/// <summary>
6993
/// Cached vector 3 reference to the new raycast position.
7094
/// <remarks>Only used to update UI raycast results.</remarks>
7195
/// </summary>
7296
private Vector3 newUiRaycastPosition = Vector3.zero;
7397

74-
/// <summary>
75-
/// Camera to use for raycasting uGUI pointer events.
76-
/// </summary>
77-
[SerializeField]
78-
[Tooltip("Camera to use for raycasting uGUI pointer events.")]
79-
private Camera uiRaycastCamera = null;
80-
81-
/// <summary>
82-
/// The Camera the Event System uses to raycast against.
83-
/// <para><remarks>Every uGUI canvas in your scene should use this camera as its event camera.</remarks></para>
84-
/// </summary>
85-
public Camera UIRaycastCamera
86-
{
87-
get
88-
{
89-
if (uiRaycastCamera == null)
90-
{
91-
CreateUiRaycastCamera();
92-
}
93-
94-
return uiRaycastCamera;
95-
}
96-
}
97-
98-
/// <summary>
99-
/// To tap on a hologram even when not focused on,
100-
/// set OverrideFocusedObject to desired game object.
101-
/// If it's null, then focused object will be used.
102-
/// </summary>
103-
public GameObject OverrideFocusedObject { get; set; }
104-
10598
[Serializable]
10699
private class PointerData : IPointerResult, IEquatable<PointerData>
107100
{
108101
public readonly IMixedRealityPointer Pointer;
109-
private FocusDetails focusDetails;
110102

111-
private GraphicInputEventData graphicData;
103+
/// <inheritdoc />
104+
public Vector3 StartPoint { get; private set; }
105+
/// <inheritdoc />
106+
public FocusDetails Details { get; private set; }
107+
/// <inheritdoc />
108+
public GameObject CurrentPointerTarget { get; private set; }
109+
/// <inheritdoc />
110+
public GameObject PreviousPointerTarget { get; private set; }
111+
/// <inheritdoc />
112+
public int RayStepIndex { get; private set; }
113+
114+
/// <summary>
115+
/// The graphic input event data used for raycasting uGUI elements.
116+
/// </summary>
112117
public GraphicInputEventData GraphicEventData
113118
{
114119
get
@@ -123,6 +128,9 @@ public GraphicInputEventData GraphicEventData
123128
return graphicData;
124129
}
125130
}
131+
private GraphicInputEventData graphicData;
132+
133+
private FocusDetails focusDetails;
126134

127135
public PointerData(IMixedRealityPointer pointer)
128136
{
@@ -188,13 +196,15 @@ public void ResetFocusedObjects(bool clearPreviousObject = true)
188196
CurrentPointerTarget = null;
189197
}
190198

199+
/// <inheritdoc />
191200
public bool Equals(PointerData other)
192201
{
193202
if (ReferenceEquals(null, other)) return false;
194203
if (ReferenceEquals(this, other)) return true;
195204
return Pointer.PointerId == other.Pointer.PointerId;
196205
}
197206

207+
/// <inheritdoc />
198208
public override bool Equals(object obj)
199209
{
200210
if (ReferenceEquals(null, obj)) return false;
@@ -203,16 +213,11 @@ public override bool Equals(object obj)
203213
return Equals((PointerData)obj);
204214
}
205215

216+
/// <inheritdoc />
206217
public override int GetHashCode()
207218
{
208219
return Pointer != null ? Pointer.GetHashCode() : 0;
209220
}
210-
211-
public Vector3 StartPoint { get; private set; }
212-
public FocusDetails Details { get; private set; }
213-
public GameObject CurrentPointerTarget { get; private set; }
214-
public GameObject PreviousPointerTarget { get; private set; }
215-
public int RayStepIndex { get; private set; }
216221
}
217222

218223
#region MonoBehaviour Implementation
@@ -246,11 +251,7 @@ private void Update()
246251

247252
#region Focus Details by EventData
248253

249-
/// <summary>
250-
/// Gets the currently focused object based on specified the event data.
251-
/// </summary>
252-
/// <param name="eventData"></param>
253-
/// <returns>Currently focused <see cref="GameObject"/> for the events input source.</returns>
254+
/// <inheritdoc />
254255
public GameObject GetFocusedObject(BaseInputEventData eventData)
255256
{
256257
Debug.Assert(eventData != null);
@@ -266,12 +267,7 @@ public GameObject GetFocusedObject(BaseInputEventData eventData)
266267
return graphicInputEventData.selectedObject;
267268
}
268269

269-
/// <summary>
270-
/// Try to get the focus details based on the specified event data.
271-
/// </summary>
272-
/// <param name="eventData"></param>
273-
/// <param name="focusDetails"></param>
274-
/// <returns>True, if event data pointer input source is registered.</returns>
270+
/// <inheritdoc />
275271
public bool TryGetFocusDetails(BaseInputEventData eventData, out FocusDetails focusDetails)
276272
{
277273
foreach (var pointerData in pointers)
@@ -287,12 +283,7 @@ public bool TryGetFocusDetails(BaseInputEventData eventData, out FocusDetails fo
287283
return false;
288284
}
289285

290-
/// <summary>
291-
/// Try to get the registered pointer source that raised the event.
292-
/// </summary>
293-
/// <param name="eventData"></param>
294-
/// <param name="pointer"></param>
295-
/// <returns>True, if event datas pointer input source is registered.</returns>
286+
/// <inheritdoc />
296287
public bool TryGetPointingSource(BaseInputEventData eventData, out IMixedRealityPointer pointer)
297288
{
298289
foreach (var pointerData in pointers)
@@ -312,12 +303,7 @@ public bool TryGetPointingSource(BaseInputEventData eventData, out IMixedReality
312303

313304
#region Focus Details by IMixedRealityPointer
314305

315-
/// <summary>
316-
/// Gets the currently focused object for the pointing source.
317-
/// <para><remarks>If the pointing source is not registered, then the Gaze's Focused <see cref="GameObject"/> is returned.</remarks></para>
318-
/// </summary>
319-
/// <param name="pointingSource"></param>
320-
/// <returns>Currently Focused Object.</returns>
306+
/// <inheritdoc />
321307
public GameObject GetFocusedObject(IMixedRealityPointer pointingSource)
322308
{
323309
if (OverrideFocusedObject != null) { return OverrideFocusedObject; }
@@ -332,11 +318,7 @@ public GameObject GetFocusedObject(IMixedRealityPointer pointingSource)
332318
return focusDetails.Object;
333319
}
334320

335-
/// <summary>
336-
/// Gets the currently focused object for the pointing source.
337-
/// </summary>
338-
/// <param name="pointer"></param>
339-
/// <param name="focusDetails"></param>
321+
/// <inheritdoc />
340322
public bool TryGetFocusDetails(IMixedRealityPointer pointer, out FocusDetails focusDetails)
341323
{
342324
foreach (var pointerData in pointers)
@@ -352,11 +334,7 @@ public bool TryGetFocusDetails(IMixedRealityPointer pointer, out FocusDetails fo
352334
return false;
353335
}
354336

355-
/// <summary>
356-
/// Get the Graphic Event Data for the specified pointing source.
357-
/// </summary>
358-
/// <param name="pointer"></param>
359-
/// <returns></returns>
337+
/// <inheritdoc />
360338
public GraphicInputEventData GetSpecificPointerGraphicEventData(IMixedRealityPointer pointer)
361339
{
362340
return GetPointerData(pointer)?.GraphicEventData;
@@ -366,10 +344,7 @@ public GraphicInputEventData GetSpecificPointerGraphicEventData(IMixedRealityPoi
366344

367345
#region Utilities
368346

369-
/// <summary>
370-
/// Generate a new unique pointer id.
371-
/// </summary>
372-
/// <returns></returns>
347+
/// <inheritdoc />
373348
public uint GenerateNewPointerId()
374349
{
375350
var newId = (uint)UnityEngine.Random.Range(1, int.MaxValue);
@@ -438,22 +413,14 @@ public void UpdateCanvasEventSystems()
438413
}
439414
}
440415

441-
/// <summary>
442-
/// Checks if the pointer is registered with the Focus Manager.
443-
/// </summary>
444-
/// <param name="pointer"></param>
445-
/// <returns>True, if registered, otherwise false.</returns>
416+
/// <inheritdoc />
446417
public bool IsPointerRegistered(IMixedRealityPointer pointer)
447418
{
448419
Debug.Assert(pointer.PointerId != 0, $"{pointer} does not have a valid pointer id!");
449420
return GetPointerData(pointer) != null;
450421
}
451422

452-
/// <summary>
453-
/// Registers the pointer with the Focus Manager.
454-
/// </summary>
455-
/// <param name="pointer"></param>
456-
/// <returns>True, if the pointer was registered, false if the pointer was previously registered.</returns>
423+
/// <inheritdoc />
457424
public bool RegisterPointer(IMixedRealityPointer pointer)
458425
{
459426
Debug.Assert(pointer.PointerId != 0, $"{pointer} does not have a valid pointer id!");
@@ -464,11 +431,7 @@ public bool RegisterPointer(IMixedRealityPointer pointer)
464431
return true;
465432
}
466433

467-
/// <summary>
468-
/// Unregisters the pointer with the Focus Manager.
469-
/// </summary>
470-
/// <param name="pointer"></param>
471-
/// <returns>True, if the pointer was unregistered, false if the pointer was not registered.</returns>
434+
/// <inheritdoc />
472435
public bool UnregisterPointer(IMixedRealityPointer pointer)
473436
{
474437
Debug.Assert(pointer.PointerId != 0, $"{pointer} does not have a valid pointer id!");

Assets/MixedRealityToolkit/InputSystem/MixedRealityInputManager.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,7 @@ public override void HandleEvent<T>(BaseEventData eventData, ExecuteEvents.Event
289289
/// <summary>
290290
/// Register a <see cref="GameObject"/> to listen to events that will receive all input events, regardless
291291
/// of which other <see cref="GameObject"/>s might have handled the event beforehand.
292+
/// <remarks>Useful for listening to events when the <see cref="GameObject"/> is currently not being raycasted against by the <see cref="FocusProvider"/>.</remarks>
292293
/// </summary>
293294
/// <param name="listener">Listener to add.</param>
294295
public override void Register(GameObject listener)

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

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,94 @@ namespace Microsoft.MixedReality.Toolkit.Internal.Interfaces.InputSystem
1313
/// </summary>
1414
public interface IMixedRealityFocusProvider : IMixedRealitySourceStateHandler
1515
{
16+
/// <summary>
17+
/// Maximum distance at which all pointers can collide with an object, unless it has an override extent.
18+
/// </summary>
1619
float GlobalPointingExtent { get; }
20+
21+
/// <summary>
22+
/// The Camera the <see cref="UnityEngine.EventSystems.EventSystem"/> uses to raycast against.
23+
/// <para><remarks>Every uGUI canvas in your scene should use this camera as its event camera.</remarks></para>
24+
/// </summary>
1725
Camera UIRaycastCamera { get; }
26+
27+
/// <summary>
28+
/// To tap on a hologram even when not focused on,
29+
/// set OverrideFocusedObject to desired game object.
30+
/// If it's null, then focused object will be used.
31+
/// </summary>
1832
GameObject OverrideFocusedObject { get; set; }
33+
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>
1939
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>
2047
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 datas pointer input source is registered.</returns>
2155
bool TryGetPointingSource(BaseInputEventData eventData, out IMixedRealityPointer pointer);
56+
57+
/// <summary>
58+
/// Gets the currently focused object for the pointing source.
59+
/// <para><remarks>If the pointing source is not registered, then the Gaze's Focused <see cref="GameObject"/> is returned.</remarks></para>
60+
/// </summary>
61+
/// <param name="pointingSource"></param>
62+
/// <returns>Currently Focused Object.</returns>
2263
GameObject GetFocusedObject(IMixedRealityPointer pointingSource);
64+
65+
/// <summary>
66+
/// Gets the currently focused object for the pointing source.
67+
/// </summary>
68+
/// <param name="pointer"></param>
69+
/// <param name="focusDetails"></param>
2370
bool TryGetFocusDetails(IMixedRealityPointer pointer, out FocusDetails focusDetails);
71+
72+
/// <summary>
73+
/// Get the Graphic Event Data for the specified pointing source.
74+
/// </summary>
75+
/// <param name="pointer"></param>
76+
/// <returns></returns>
2477
GraphicInputEventData GetSpecificPointerGraphicEventData(IMixedRealityPointer pointer);
78+
79+
/// <summary>
80+
/// Generate a new unique pointer id.
81+
/// </summary>
82+
/// <returns></returns>
2583
uint GenerateNewPointerId();
84+
85+
/// <summary>
86+
/// Checks if the pointer is registered with the Focus Manager.
87+
/// </summary>
88+
/// <param name="pointer"></param>
89+
/// <returns>True, if registered, otherwise false.</returns>
2690
bool IsPointerRegistered(IMixedRealityPointer pointer);
91+
92+
/// <summary>
93+
/// Registers the pointer with the Focus Manager.
94+
/// </summary>
95+
/// <param name="pointer"></param>
96+
/// <returns>True, if the pointer was registered, false if the pointer was previously registered.</returns>
2797
bool RegisterPointer(IMixedRealityPointer pointer);
98+
99+
/// <summary>
100+
/// Unregisters the pointer with the Focus Manager.
101+
/// </summary>
102+
/// <param name="pointer"></param>
103+
/// <returns>True, if the pointer was unregistered, false if the pointer was not registered.</returns>
28104
bool UnregisterPointer(IMixedRealityPointer pointer);
29105
}
30106
}

0 commit comments

Comments
 (0)