Skip to content

Commit 413237e

Browse files
Merge pull request #2533 from StephenHodgson/vNEXT-Pointers2
vNEXT Basic Controller Pointers.
2 parents 098fc9e + 831eb06 commit 413237e

File tree

46 files changed

+1921
-392
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+1921
-392
lines changed

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

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -512,7 +512,7 @@ private void UpdatePointer(PointerData pointer)
512512
pointer.Pointer.OnPreRaycast();
513513

514514
// If pointer interaction isn't enabled, clear its result object and return
515-
if (!pointer.Pointer.InteractionEnabled)
515+
if (!pointer.Pointer.IsInteractionEnabled)
516516
{
517517
// Don't clear the previous focused object since we still want to trigger FocusExit events
518518
pointer.ResetFocusedObjects(false);
@@ -523,7 +523,7 @@ private void UpdatePointer(PointerData pointer)
523523
// Keep the focus objects the same
524524
// This will ensure that we execute events on those objects
525525
// even if the pointer isn't pointing at them
526-
if (!pointer.Pointer.FocusLocked)
526+
if (!pointer.Pointer.IsFocusLocked)
527527
{
528528
// Otherwise, continue
529529
var prioritizedLayerMasks = (pointer.Pointer.PrioritizedLayerMasksOverride ?? pointingRaycastLayerMasks);
@@ -809,9 +809,9 @@ public void OnSourceDetected(SourceStateEventData eventData)
809809
// If our input source does not have any pointers, then skip.
810810
if (eventData.InputSource.Pointers == null) { return; }
811811

812-
foreach (var sourcePointer in eventData.InputSource.Pointers)
812+
for (var i = 0; i < eventData.InputSource.Pointers.Length; i++)
813813
{
814-
RegisterPointer(sourcePointer);
814+
RegisterPointer(eventData.InputSource.Pointers[i]);
815815

816816
// Special Registration for Gaze
817817
if (eventData.InputSource.SourceId == InputSystem.GazeProvider.GazeInputSource.SourceId)
@@ -820,7 +820,7 @@ public void OnSourceDetected(SourceStateEventData eventData)
820820

821821
if (gazeProviderPointingData == null)
822822
{
823-
gazeProviderPointingData = new PointerData(sourcePointer);
823+
gazeProviderPointingData = new PointerData(eventData.InputSource.Pointers[i]);
824824
}
825825

826826
Debug.Assert(gazeProviderPointingData != null);
@@ -833,22 +833,23 @@ public void OnSourceLost(SourceStateEventData eventData)
833833
// If the input source does not have pointers, then skip.
834834
if (eventData.InputSource.Pointers == null) { return; }
835835

836-
foreach (var sourcePointer in eventData.InputSource.Pointers)
836+
for (var i = 0; i < eventData.InputSource.Pointers.Length; i++)
837837
{
838838
// Special unregistration for Gaze
839839
if (eventData.InputSource.SourceId == InputSystem.GazeProvider.GazeInputSource.SourceId)
840840
{
841+
Debug.Log("UnRegistering focus pointer");
841842
Debug.Assert(gazeProviderPointingData != null);
842843

843844
// If the source lost is the gaze input source, then reset it.
844-
if (sourcePointer.PointerId == gazeProviderPointingData.Pointer.PointerId)
845+
if (eventData.InputSource.Pointers[i].PointerId == gazeProviderPointingData.Pointer.PointerId)
845846
{
846847
gazeProviderPointingData.ResetFocusedObjects();
847848
gazeProviderPointingData = null;
848849
}
849850
}
850851

851-
UnregisterPointer(sourcePointer);
852+
UnregisterPointer(eventData.InputSource.Pointers[i]);
852853
}
853854
}
854855

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

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
using Microsoft.MixedReality.Toolkit.InputSystem.Pointers;
55
using Microsoft.MixedReality.Toolkit.InputSystem.Sources;
6+
using Microsoft.MixedReality.Toolkit.Internal.Interfaces;
67
using Microsoft.MixedReality.Toolkit.Internal.Interfaces.InputSystem;
78
using Microsoft.MixedReality.Toolkit.Internal.Utilities;
89
using Microsoft.MixedReality.Toolkit.Internal.Utilities.Physics;
@@ -140,16 +141,25 @@ public InternalGazePointer(GazeProvider gazeProvider, string pointerName, IMixed
140141
PointerExtent = pointerExtent;
141142
this.gazeTransform = gazeTransform;
142143
this.stabilizer = stabilizer;
143-
InteractionEnabled = true;
144+
IsInteractionEnabled = true;
144145
}
145146

147+
/// <inheritdoc />
148+
public override IMixedRealityController Controller { get; set; }
149+
150+
/// <inheritdoc />
146151
public override IMixedRealityInputSource InputSourceParent { get; protected set; }
147152

148-
public void SetGazeInputSourceParent(IMixedRealityInputSource gazeInputSource)
153+
/// <summary>
154+
/// Only for use when initializing Gaze Pointer on startup.
155+
/// </summary>
156+
/// <param name="gazeInputSource"></param>
157+
internal void SetGazeInputSourceParent(IMixedRealityInputSource gazeInputSource)
149158
{
150159
InputSourceParent = gazeInputSource;
151160
}
152161

162+
/// <inheritdoc />
153163
public override void OnPreRaycast()
154164
{
155165
Vector3 newGazeOrigin = gazeTransform.position;
@@ -163,7 +173,7 @@ public override void OnPreRaycast()
163173
newGazeNormal = stabilizer.StableRay.direction;
164174
}
165175

166-
Rays[0].UpdateRayStep(newGazeOrigin, newGazeOrigin + (newGazeNormal * (PointerExtent ?? InputSystem.FocusProvider.GlobalPointingExtent)));
176+
Rays[0].UpdateRayStep(newGazeOrigin, newGazeOrigin + (newGazeNormal * PointerExtent));
167177

168178
gazeProvider.HitPosition = Rays[0].Origin + (gazeProvider.lastHitDistance * Rays[0].Direction);
169179
}
@@ -224,7 +234,7 @@ private void Start()
224234
{
225235
if (cursorPrefab != null)
226236
{
227-
var cursorObj = Instantiate(cursorPrefab, transform);
237+
var cursorObj = Instantiate(cursorPrefab);
228238
GazePointer.BaseCursor = cursorObj.GetComponent<IMixedRealityCursor>();
229239
Debug.Assert(GazePointer.BaseCursor != null, "Failed to load cursor");
230240
GazePointer.BaseCursor.Pointer = GazePointer;
@@ -287,16 +297,8 @@ protected override void OnDisable()
287297
{
288298
base.OnDisable();
289299
GazePointer.BaseCursor?.SetVisibility(false);
290-
InputSystem.RaiseSourceLost(GazeInputSource);
291300
InputSystem.FocusProvider.UnregisterPointer(GazePointer);
292-
}
293-
294-
private void OnDestroy()
295-
{
296-
if (GazePointer.BaseCursor != null)
297-
{
298-
Destroy(GazePointer.BaseCursor.GetGameObjectReference());
299-
}
301+
InputSystem.RaiseSourceLost(GazeInputSource);
300302
}
301303

302304
#endregion Monobehaiour Implementation

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

Lines changed: 58 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using Microsoft.MixedReality.Toolkit.Internal.Definitions.Utilities;
66
using Microsoft.MixedReality.Toolkit.Internal.EventDatum.Input;
77
using Microsoft.MixedReality.Toolkit.Internal.Extensions;
8+
using Microsoft.MixedReality.Toolkit.Internal.Interfaces;
89
using Microsoft.MixedReality.Toolkit.Internal.Interfaces.InputSystem.Handlers;
910
using UnityEngine;
1011

@@ -22,15 +23,7 @@ public class ControllerPoseSynchronizer : InputSystemGlobalListener, IMixedReali
2223
/// <summary>
2324
/// The handedness this controller should synchronize with.
2425
/// </summary>
25-
public Handedness Handedness
26-
{
27-
get { return handedness; }
28-
set
29-
{
30-
handedness = value;
31-
ResetControllerReference();
32-
}
33-
}
26+
public Handedness Handedness => handedness;
3427

3528
[SerializeField]
3629
[Tooltip("Disables child GameObjects when the controller source is lost.")]
@@ -48,90 +41,96 @@ public bool DisableChildren
4841
/// <summary>
4942
/// Is the controller this Synchronizer is registered to currently tracked?
5043
/// </summary>
51-
public bool IsTracked { get; private set; } = false;
44+
public bool IsTracked { get; protected set; } = false;
45+
46+
/// <summary>
47+
/// The current tracking state of the assigned <see cref="IMixedRealityController"/>
48+
/// </summary>
49+
protected TrackingState TrackingState = TrackingState.NotTracked;
5250

53-
private TrackingState lastTrackingState = TrackingState.NotTracked;
51+
/// <summary>
52+
/// The currently assigned Controller.
53+
/// </summary>
54+
public virtual IMixedRealityController Controller
55+
{
56+
get { return controller; }
57+
set
58+
{
59+
handedness = value.ControllerHandedness;
60+
controller = value;
61+
}
62+
}
5463

55-
private uint controllerInputSourceId = 0;
64+
private IMixedRealityController controller;
5665

5766
#region IMixedRealitySourcePoseHandler Implementation
5867

5968
/// <inheritdoc />
6069
public virtual void OnSourceDetected(SourceStateEventData eventData)
6170
{
62-
SetControllerReference(eventData);
71+
if (Controller == null ||
72+
eventData.Controller == null ||
73+
eventData.Controller.InputSource.SourceId != Controller.InputSource.SourceId)
74+
{
75+
return;
76+
}
77+
78+
if (eventData.Controller.ControllerHandedness == Handedness &&
79+
eventData.Controller.InputSource.SourceId == Controller.InputSource.SourceId)
80+
{
81+
82+
if (disableChildren)
83+
{
84+
gameObject.SetChildrenActive(true);
85+
}
86+
}
6387
}
6488

6589
/// <inheritdoc />
6690
public virtual void OnSourceLost(SourceStateEventData eventData)
6791
{
68-
if (eventData.Controller.ControllerHandedness == Handedness)
92+
if (Controller == null ||
93+
eventData.Controller == null ||
94+
eventData.Controller.InputSource.SourceId != Controller.InputSource.SourceId)
95+
{
96+
return;
97+
}
98+
99+
if (eventData.Controller?.ControllerHandedness == Handedness)
69100
{
70-
ResetControllerReference();
101+
IsTracked = false;
102+
TrackingState = TrackingState.NotTracked;
103+
104+
if (disableChildren)
105+
{
106+
gameObject.SetChildrenActive(false);
107+
}
71108
}
72109
}
73110

74111
/// <inheritdoc />
75112
public virtual void OnSourcePoseChanged(SourcePoseEventData eventData)
76113
{
77-
if (controllerInputSourceId == 0)
78-
{
79-
SetControllerReference(eventData);
80-
}
81-
82-
if (eventData.Controller.InputSource.SourceId != controllerInputSourceId)
114+
if (Controller == null ||
115+
eventData.Controller == null ||
116+
eventData.Controller.InputSource.SourceId != Controller.InputSource.SourceId)
83117
{
84118
return;
85119
}
86120

87-
if (eventData.TrackingState != lastTrackingState)
121+
if (eventData.TrackingState != TrackingState)
88122
{
89123
IsTracked = eventData.TrackingState == TrackingState.Tracked;
90-
lastTrackingState = eventData.TrackingState;
124+
TrackingState = eventData.TrackingState;
91125
}
92126

93-
if (lastTrackingState == TrackingState.Tracked)
127+
if (TrackingState == TrackingState.Tracked)
94128
{
95129
transform.position = eventData.MixedRealityPose.Position;
96130
transform.rotation = eventData.MixedRealityPose.Rotation;
97131
}
98132
}
99133

100134
#endregion IMixedRealitySourcePoseHandler Implementation
101-
102-
#region Monobehaviour Implementation
103-
104-
protected override void OnEnable()
105-
{
106-
ResetControllerReference();
107-
108-
// Subscribe to interaction events
109-
base.OnEnable();
110-
}
111-
112-
#endregion Monobehaviour Implementation
113-
114-
private void ResetControllerReference()
115-
{
116-
controllerInputSourceId = 0;
117-
118-
if (DisableChildren)
119-
{
120-
gameObject.SetChildrenActive(false);
121-
}
122-
}
123-
124-
private void SetControllerReference(SourceStateEventData eventData)
125-
{
126-
if (eventData.Controller.ControllerHandedness == Handedness)
127-
{
128-
controllerInputSourceId = eventData.Controller.InputSource.SourceId;
129-
130-
if (DisableChildren)
131-
{
132-
gameObject.SetChildrenActive(true);
133-
}
134-
}
135-
}
136135
}
137136
}

0 commit comments

Comments
 (0)