Skip to content

Commit 20d234e

Browse files
author
David Kline
authored
Merge pull request #2412 from StephenHodgson/vNEXT-DocUpdate
Updated some docs focused around focus provider and pointers.
2 parents bca5225 + a54ed4b commit 20d234e

File tree

4 files changed

+159
-101
lines changed

4 files changed

+159
-101
lines changed

Assets/MixedRealityToolkit/InputSystem/Focus/FocusProvider.cs

Lines changed: 66 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 a GameObject, 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,35 @@ 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+
106+
/// <inheritdoc />
107+
public FocusDetails Details { get; private set; }
108+
109+
/// <inheritdoc />
110+
public GameObject CurrentPointerTarget { get; private set; }
111+
112+
/// <inheritdoc />
113+
public GameObject PreviousPointerTarget { get; private set; }
114+
115+
/// <inheritdoc />
116+
public int RayStepIndex { get; private set; }
117+
118+
/// <summary>
119+
/// The graphic input event data used for raycasting uGUI elements.
120+
/// </summary>
112121
public GraphicInputEventData GraphicEventData
113122
{
114123
get
@@ -123,6 +132,9 @@ public GraphicInputEventData GraphicEventData
123132
return graphicData;
124133
}
125134
}
135+
private GraphicInputEventData graphicData;
136+
137+
private FocusDetails focusDetails;
126138

127139
public PointerData(IMixedRealityPointer pointer)
128140
{
@@ -188,13 +200,15 @@ public void ResetFocusedObjects(bool clearPreviousObject = true)
188200
CurrentPointerTarget = null;
189201
}
190202

203+
/// <inheritdoc />
191204
public bool Equals(PointerData other)
192205
{
193206
if (ReferenceEquals(null, other)) return false;
194207
if (ReferenceEquals(this, other)) return true;
195208
return Pointer.PointerId == other.Pointer.PointerId;
196209
}
197210

211+
/// <inheritdoc />
198212
public override bool Equals(object obj)
199213
{
200214
if (ReferenceEquals(null, obj)) return false;
@@ -203,16 +217,11 @@ public override bool Equals(object obj)
203217
return Equals((PointerData)obj);
204218
}
205219

220+
/// <inheritdoc />
206221
public override int GetHashCode()
207222
{
208223
return Pointer != null ? Pointer.GetHashCode() : 0;
209224
}
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; }
216225
}
217226

218227
#region MonoBehaviour Implementation
@@ -246,11 +255,7 @@ private void Update()
246255

247256
#region Focus Details by EventData
248257

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>
258+
/// <inheritdoc />
254259
public GameObject GetFocusedObject(BaseInputEventData eventData)
255260
{
256261
Debug.Assert(eventData != null);
@@ -266,12 +271,7 @@ public GameObject GetFocusedObject(BaseInputEventData eventData)
266271
return graphicInputEventData.selectedObject;
267272
}
268273

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>
274+
/// <inheritdoc />
275275
public bool TryGetFocusDetails(BaseInputEventData eventData, out FocusDetails focusDetails)
276276
{
277277
foreach (var pointerData in pointers)
@@ -287,12 +287,7 @@ public bool TryGetFocusDetails(BaseInputEventData eventData, out FocusDetails fo
287287
return false;
288288
}
289289

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>
290+
/// <inheritdoc />
296291
public bool TryGetPointingSource(BaseInputEventData eventData, out IMixedRealityPointer pointer)
297292
{
298293
foreach (var pointerData in pointers)
@@ -312,12 +307,7 @@ public bool TryGetPointingSource(BaseInputEventData eventData, out IMixedReality
312307

313308
#region Focus Details by IMixedRealityPointer
314309

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>
310+
/// <inheritdoc />
321311
public GameObject GetFocusedObject(IMixedRealityPointer pointingSource)
322312
{
323313
if (OverrideFocusedObject != null) { return OverrideFocusedObject; }
@@ -332,11 +322,7 @@ public GameObject GetFocusedObject(IMixedRealityPointer pointingSource)
332322
return focusDetails.Object;
333323
}
334324

335-
/// <summary>
336-
/// Gets the currently focused object for the pointing source.
337-
/// </summary>
338-
/// <param name="pointer"></param>
339-
/// <param name="focusDetails"></param>
325+
/// <inheritdoc />
340326
public bool TryGetFocusDetails(IMixedRealityPointer pointer, out FocusDetails focusDetails)
341327
{
342328
foreach (var pointerData in pointers)
@@ -352,11 +338,7 @@ public bool TryGetFocusDetails(IMixedRealityPointer pointer, out FocusDetails fo
352338
return false;
353339
}
354340

355-
/// <summary>
356-
/// Get the Graphic Event Data for the specified pointing source.
357-
/// </summary>
358-
/// <param name="pointer"></param>
359-
/// <returns></returns>
341+
/// <inheritdoc />
360342
public GraphicInputEventData GetSpecificPointerGraphicEventData(IMixedRealityPointer pointer)
361343
{
362344
return GetPointerData(pointer)?.GraphicEventData;
@@ -366,10 +348,7 @@ public GraphicInputEventData GetSpecificPointerGraphicEventData(IMixedRealityPoi
366348

367349
#region Utilities
368350

369-
/// <summary>
370-
/// Generate a new unique pointer id.
371-
/// </summary>
372-
/// <returns></returns>
351+
/// <inheritdoc />
373352
public uint GenerateNewPointerId()
374353
{
375354
var newId = (uint)UnityEngine.Random.Range(1, int.MaxValue);
@@ -438,22 +417,14 @@ public void UpdateCanvasEventSystems()
438417
}
439418
}
440419

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>
420+
/// <inheritdoc />
446421
public bool IsPointerRegistered(IMixedRealityPointer pointer)
447422
{
448423
Debug.Assert(pointer.PointerId != 0, $"{pointer} does not have a valid pointer id!");
449424
return GetPointerData(pointer) != null;
450425
}
451426

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>
427+
/// <inheritdoc />
457428
public bool RegisterPointer(IMixedRealityPointer pointer)
458429
{
459430
Debug.Assert(pointer.PointerId != 0, $"{pointer} does not have a valid pointer id!");
@@ -464,11 +435,7 @@ public bool RegisterPointer(IMixedRealityPointer pointer)
464435
return true;
465436
}
466437

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>
438+
/// <inheritdoc />
472439
public bool UnregisterPointer(IMixedRealityPointer pointer)
473440
{
474441
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 a <see cref="GameObject"/>, 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)