11// Copyright (c) Microsoft Corporation. All rights reserved.
22// Licensed under the MIT License. See LICENSE in the project root for license information.
33
4+ using Microsoft . MixedReality . Toolkit . Core . Definitions . InputSystem ;
45using Microsoft . MixedReality . Toolkit . Core . Definitions . Physics ;
56using Microsoft . MixedReality . Toolkit . Core . EventDatum . Input ;
67using Microsoft . MixedReality . Toolkit . Core . Extensions ;
8+ using Microsoft . MixedReality . Toolkit . Core . Interfaces ;
79using Microsoft . MixedReality . Toolkit . Core . Interfaces . InputSystem ;
810using Microsoft . MixedReality . Toolkit . Core . Services ;
911using Microsoft . MixedReality . Toolkit . Core . Utilities ;
@@ -19,8 +21,14 @@ namespace Microsoft.MixedReality.Toolkit.Services.InputSystem
1921 /// The focus provider handles the focused objects per input source.
2022 /// <remarks>There are convenience properties for getting only Gaze Pointer if needed.</remarks>
2123 /// </summary>
22- public class FocusProvider : BaseService , IMixedRealityFocusProvider
24+ public class FocusProvider : BaseDataProvider , IMixedRealityFocusProvider
2325 {
26+ public FocusProvider (
27+ IMixedRealityServiceRegistrar registrar ,
28+ IMixedRealityInputSystem inputSystem ,
29+ MixedRealityInputSystemProfile profile ) : base ( registrar , inputSystem , null , DefaultPriority , profile )
30+ { }
31+
2432 private readonly HashSet < PointerData > pointers = new HashSet < PointerData > ( ) ;
2533 private readonly HashSet < GameObject > pendingOverallFocusEnterSet = new HashSet < GameObject > ( ) ;
2634 private readonly HashSet < GameObject > pendingOverallFocusExitSet = new HashSet < GameObject > ( ) ;
@@ -39,11 +47,13 @@ float IMixedRealityFocusProvider.GlobalPointingExtent
3947 {
4048 get
4149 {
42- if ( MixedRealityToolkit . Instance . HasActiveProfile &&
43- MixedRealityToolkit . Instance . ActiveProfile . IsInputSystemEnabled &&
44- MixedRealityToolkit . Instance . ActiveProfile . InputSystemProfile . PointerProfile != null )
50+ MixedRealityInputSystemProfile profile = ConfigurationProfile as MixedRealityInputSystemProfile ;
51+
52+ if ( ( Service != null ) &&
53+ ( profile != null ) &&
54+ profile . PointerProfile != null )
4555 {
46- return MixedRealityToolkit . Instance . ActiveProfile . InputSystemProfile . PointerProfile . PointingExtent ;
56+ return profile . PointerProfile . PointingExtent ;
4757 }
4858
4959 return 10f ;
@@ -59,11 +69,13 @@ public LayerMask[] FocusLayerMasks
5969 {
6070 if ( focusLayerMasks == null )
6171 {
62- if ( MixedRealityToolkit . Instance . HasActiveProfile &&
63- MixedRealityToolkit . Instance . ActiveProfile . IsInputSystemEnabled &&
64- MixedRealityToolkit . Instance . ActiveProfile . InputSystemProfile . PointerProfile != null )
72+ MixedRealityInputSystemProfile profile = ConfigurationProfile as MixedRealityInputSystemProfile ;
73+
74+ if ( ( Service != null ) &&
75+ ( profile != null ) &&
76+ profile . PointerProfile != null )
6577 {
66- return focusLayerMasks = MixedRealityToolkit . Instance . ActiveProfile . InputSystemProfile . PointerProfile . PointingRaycastLayerMasks ;
78+ return focusLayerMasks = profile . PointerProfile . PointingRaycastLayerMasks ;
6779 }
6880
6981 return focusLayerMasks = new LayerMask [ ] { Physics . DefaultRaycastLayers } ;
@@ -102,21 +114,21 @@ private bool IsSetupValid
102114 {
103115 get
104116 {
105- if ( ! MixedRealityToolkit . Instance . ActiveProfile . IsInputSystemEnabled ) { return false ; }
106-
107- if ( MixedRealityToolkit . InputSystem == null )
117+ if ( Service == null )
108118 {
109119 Debug . LogError ( $ "Unable to start { Name } . An Input System is required for this feature.") ;
110120 return false ;
111121 }
112122
113- if ( MixedRealityToolkit . Instance . ActiveProfile . InputSystemProfile == null )
123+ MixedRealityInputSystemProfile profile = ConfigurationProfile as MixedRealityInputSystemProfile ;
124+
125+ if ( profile == null )
114126 {
115127 Debug . LogError ( $ "Unable to start { Name } . An Input System Profile is required for this feature.") ;
116128 return false ;
117129 }
118130
119- if ( MixedRealityToolkit . Instance . ActiveProfile . InputSystemProfile . PointerProfile == null )
131+ if ( profile . PointerProfile == null )
120132 {
121133 Debug . LogError ( $ "Unable to start { Name } . An Pointer Profile is required for this feature.") ;
122134 return false ;
@@ -563,15 +575,18 @@ private void UpdatePointers()
563575 {
564576 int pointerCount = 0 ;
565577
578+ MixedRealityInputSystemProfile profile = ConfigurationProfile as MixedRealityInputSystemProfile ;
579+ if ( profile == null ) { return ; }
580+
566581 foreach ( var pointer in pointers )
567582 {
568583 UpdatePointer ( pointer ) ;
569584
570- var pointerProfile = MixedRealityToolkit . Instance . ActiveProfile . InputSystemProfile . PointerProfile ;
585+ var pointerProfile = profile . PointerProfile ;
571586
572587 if ( pointerProfile != null && pointerProfile . DebugDrawPointingRays )
573588 {
574- MixedRealityRaycaster . DebugEnabled = MixedRealityToolkit . Instance . ActiveProfile . InputSystemProfile . PointerProfile . DebugDrawPointingRays ;
589+ MixedRealityRaycaster . DebugEnabled = pointerProfile . DebugDrawPointingRays ;
575590
576591 Color rayColor ;
577592
0 commit comments