@@ -169,14 +169,6 @@ private bool IsSetupValid
169
169
}
170
170
}
171
171
172
- /// <summary>
173
- /// GazeProvider is a little special, so we keep track of it even if it's not a registered pointer. For the sake
174
- /// of StabilizationPlaneModifier and potentially other components that care where the user's looking, we need
175
- /// to do a gaze raycast even if gaze isn't used for focus.
176
- /// </summary>
177
- private PointerData gazeProviderPointingData ;
178
- private PointerHitResult gazeHitResult ;
179
-
180
172
/// <summary>
181
173
/// Cached <see href="https://docs.unity3d.com/ScriptReference/Vector3.html">Vector3</see> reference to the new raycast position.
182
174
/// </summary>
@@ -569,31 +561,42 @@ public override void Update()
569
561
570
562
private static readonly ProfilerMarker UpdateGazeProviderPerfMarker = new ProfilerMarker ( "[MRTK] FocusProvider.UpdateGazeProvider" ) ;
571
563
564
+ /// <summary>
565
+ /// GazeProvider is a little special, so we keep track of it even if it's not a registered pointer. For the sake
566
+ /// of StabilizationPlaneModifier and potentially other components that care where the user's looking, we need
567
+ /// to do a gaze raycast even if gaze isn't used for focus.
568
+ /// </summary>
569
+ private PointerEventData gazeProviderPointingData ;
570
+ private PointerHitResult gazeHitResult ;
571
+
572
572
/// <summary>
573
573
/// Updates the gaze raycast provider even in scenarios where gaze isn't used for focus
574
574
/// </summary>
575
575
private void UpdateGazeProvider ( )
576
576
{
577
577
using ( UpdateGazeProviderPerfMarker . Auto ( ) )
578
578
{
579
- // The gaze hit result may be populated from previous raycasts this frame, only recompute
579
+ // The gaze hit result may be populated from the UpdatePointers call. If it has not, then perform
580
580
// another raycast if it's not populated
581
581
if ( gazeHitResult == null )
582
582
{
583
- if ( gazeProviderPointingData ? . Pointer != null )
583
+ IMixedRealityPointer gazePointer = CoreServices . InputSystem . GazeProvider ? . GazePointer ;
584
+ // Check that the gazePointer isn't null and that it has been properly registered as a pointer.
585
+ if ( gazePointer != null && gazeProviderPointingData != null )
584
586
{
585
587
// get 3d hit
588
+ // This is unneccessary since the gaze pointer has been registered normally along with the other pointers(?)
586
589
hitResult3d . Clear ( ) ;
587
590
var raycastProvider = CoreServices . InputSystem . RaycastProvider ;
588
- LayerMask [ ] prioritizedLayerMasks = ( gazeProviderPointingData . Pointer . PrioritizedLayerMasksOverride ?? FocusLayerMasks ) ;
589
- QueryScene ( gazeProviderPointingData . Pointer , raycastProvider , prioritizedLayerMasks ,
591
+ LayerMask [ ] prioritizedLayerMasks = ( gazePointer . PrioritizedLayerMasksOverride ?? FocusLayerMasks ) ;
592
+ QueryScene ( gazePointer , raycastProvider , prioritizedLayerMasks ,
590
593
hitResult3d , maxQuerySceneResults , focusIndividualCompoundCollider ) ;
591
594
592
595
if ( shouldUseGraphicsRaycast )
593
596
{
594
597
// get ui hit
595
598
hitResultUi . Clear ( ) ;
596
- RaycastGraphics ( gazeProviderPointingData . Pointer , gazeProviderPointingData . GraphicEventData , prioritizedLayerMasks , hitResultUi ) ;
599
+ RaycastGraphics ( gazePointer , gazeProviderPointingData , prioritizedLayerMasks , hitResultUi ) ;
597
600
}
598
601
599
602
// set gaze hit according to distance and prioritization layer mask
@@ -605,7 +608,10 @@ private void UpdateGazeProvider()
605
608
}
606
609
}
607
610
608
- CoreServices . InputSystem . GazeProvider . UpdateGazeInfoFromHit ( gazeHitResult . raycastHit ) ;
611
+ if ( ! CoreServices . InputSystem . GazeProvider . IsNull ( ) )
612
+ {
613
+ CoreServices . InputSystem . GazeProvider . UpdateGazeInfoFromHit ( gazeHitResult . raycastHit ) ;
614
+ }
609
615
610
616
// Zero out value after every use to ensure the hit result is updated every frame.
611
617
gazeHitResult = null ;
@@ -835,11 +841,12 @@ private void RegisterPointers(IMixedRealityInputSource inputSource)
835
841
RegisterPointer ( inputSource . Pointers [ i ] ) ;
836
842
837
843
// Special Registration for Gaze
844
+ // Refreshes gazeProviderPointingData to a new reference to the current EventSystem
838
845
if ( ! CoreServices . InputSystem . GazeProvider . IsNull ( )
839
846
&& inputSource . SourceId == CoreServices . InputSystem . GazeProvider . GazeInputSource . SourceId
840
847
&& gazeProviderPointingData == null )
841
848
{
842
- gazeProviderPointingData = new PointerData ( inputSource . Pointers [ i ] ) ;
849
+ gazeProviderPointingData = new PointerEventData ( EventSystem . current ) ;
843
850
}
844
851
}
845
852
}
@@ -1084,7 +1091,8 @@ private void UpdatePointer(PointerData pointerData)
1084
1091
pointerData . UpdateHit ( hit ) ;
1085
1092
1086
1093
// set gaze hit result - make sure to include unity ui hits
1087
- if ( gazeProviderPointingData ? . Pointer != null && pointerData . Pointer . PointerId == gazeProviderPointingData . Pointer . PointerId )
1094
+ var gazePointer = CoreServices . InputSystem . GazeProvider . GazePointer ;
1095
+ if ( gazePointer != null && pointerData . Pointer . PointerId == gazePointer . PointerId )
1088
1096
{
1089
1097
gazeHitResult = hit ;
1090
1098
}
@@ -1161,7 +1169,7 @@ private void ReconcilePointers()
1161
1169
{
1162
1170
using ( ReconcilePointersPerfMarker . Auto ( ) )
1163
1171
{
1164
- var gazePointer = gazeProviderPointingData ? . Pointer as GenericPointer ;
1172
+ var gazePointer = CoreServices . InputSystem . GazeProvider ? . GazePointer as GenericPointer ;
1165
1173
NumFarPointersActive = 0 ;
1166
1174
NumNearPointersActive = 0 ;
1167
1175
int numFarPointersWithoutCursorActive = 0 ;
@@ -1559,18 +1567,19 @@ public void OnSourceLost(SourceStateEventData eventData)
1559
1567
1560
1568
pointerMediators . Remove ( eventData . SourceId ) ;
1561
1569
1570
+
1562
1571
for ( var i = 0 ; i < eventData . InputSource . Pointers . Length ; i ++ )
1563
1572
{
1573
+ var gazePointer = CoreServices . InputSystem . GazeProvider ? . GazePointer ;
1564
1574
// Special unregistration for Gaze
1565
- if ( gazeProviderPointingData ? . Pointer != null && eventData . InputSource . Pointers [ i ] . PointerId == gazeProviderPointingData . Pointer . PointerId )
1575
+ if ( gazePointer != null && eventData . InputSource . Pointers [ i ] . PointerId == gazePointer . PointerId )
1566
1576
{
1567
- // If the source lost is the gaze input source, then reset it .
1577
+ // If the source lost is the gaze input source, clear gazeProviderPointingData .
1568
1578
if ( eventData . InputSource . SourceId == CoreServices . InputSystem . GazeProvider ? . GazeInputSource . SourceId )
1569
1579
{
1570
- gazeProviderPointingData . ResetFocusedObjects ( ) ;
1571
1580
gazeProviderPointingData = null ;
1572
1581
}
1573
- // Otherwise, don't unregister the gaze pointer , since the gaze input source is still active.
1582
+ // Otherwise, don't clear gazeProviderPointingData , since the gaze input source is still active.
1574
1583
else
1575
1584
{
1576
1585
continue ;
0 commit comments