44using Microsoft . MixedReality . Toolkit . Input ;
55using Microsoft . MixedReality . Toolkit . Utilities ;
66using Microsoft . MixedReality . Toolkit . Windows . Utilities ;
7+ using Microsoft . MixedReality . Toolkit . WindowsMixedReality ;
78using Microsoft . MixedReality . Toolkit . XRSDK . Input ;
89using System ;
9- using System . Linq ;
10- using System . Collections . Generic ;
11- using UnityEngine ;
1210using UnityEngine . XR ;
13- using UnityEngine . XR . Management ;
14- #if WMR_ENABLED
15- using UnityEngine . XR . WindowsMR ;
16- #endif
17- using Unity . Profiling ;
18- using Microsoft . MixedReality . Toolkit . WindowsMixedReality ;
1911
2012#if HP_CONTROLLER_ENABLED
2113using Microsoft . MixedReality . Input ;
2214using MotionControllerHandedness = Microsoft . MixedReality . Input . Handedness ;
23- using Handedness = Microsoft . MixedReality . Toolkit . Utilities . Handedness ;
15+ using System . Collections . Generic ;
16+ using Unity . Profiling ;
2417#endif
2518
2619#if WINDOWS_UWP
@@ -57,42 +50,64 @@ public WindowsMixedRealityDeviceManager(
5750 uint priority = DefaultPriority ,
5851 BaseMixedRealityProfile profile = null ) : base ( inputSystem , name , priority , profile ) { }
5952
60- #region IMixedRealityDeviceManager Interface
53+ private bool ? isActiveLoader = null ;
54+ private bool IsActiveLoader
55+ {
56+ get
57+ {
58+ #if WMR_ENABLED
59+ if ( ! isActiveLoader . HasValue )
60+ {
61+ isActiveLoader = IsLoaderActive ( "Windows MR Loader" ) ;
62+ }
63+ #endif // WMR_ENABLED
6164
62- #if ( UNITY_WSA && DOTNETWINRT_PRESENT ) || WINDOWS_UWP
63- private IMixedRealityGazeProviderHeadOverride mixedRealityGazeProviderHeadOverride = null ;
65+ return isActiveLoader ?? false ;
66+ }
67+ }
68+
69+ #region IMixedRealityDeviceManager Interface
6470
6571 /// <inheritdoc />
6672 public override void Enable ( )
6773 {
68- base . Enable ( ) ;
69-
70- #if WMR_ENABLED
71- if ( ! XRGeneralSettings . Instance . Manager . loaders . Any ( l => l is WindowsMRLoader loader && loader . displaySubsystem != null ) )
74+ if ( ! IsActiveLoader )
7275 {
76+ IsEnabled = false ;
7377 return ;
7478 }
75- #endif
79+
80+ base . Enable ( ) ;
7681
7782 if ( WindowsMixedRealityUtilities . UtilitiesProvider == null )
7883 {
7984 WindowsMixedRealityUtilities . UtilitiesProvider = new XRSDKWindowsMixedRealityUtilitiesProvider ( ) ;
8085 }
8186
87+ #if ( UNITY_WSA && DOTNETWINRT_PRESENT ) || WINDOWS_UWP
8288 mixedRealityGazeProviderHeadOverride = Service ? . GazeProvider as IMixedRealityGazeProviderHeadOverride ;
89+ #endif // (UNITY_WSA && DOTNETWINRT_PRESENT) || WINDOWS_UWP
8390
8491#if HP_CONTROLLER_ENABLED
8592 // Listens to events to track the HP Motion Controller
8693 motionControllerWatcher = new MotionControllerWatcher ( ) ;
8794 motionControllerWatcher . MotionControllerAdded += AddTrackedMotionController ;
8895 motionControllerWatcher . MotionControllerRemoved += RemoveTrackedMotionController ;
8996 var nowait = motionControllerWatcher . StartAsync ( ) ;
90- #endif
97+ #endif // HP_CONTROLLER_ENABLED
9198 }
9299
100+ #if ( UNITY_WSA && DOTNETWINRT_PRESENT ) || WINDOWS_UWP
101+ private IMixedRealityGazeProviderHeadOverride mixedRealityGazeProviderHeadOverride = null ;
102+
93103 /// <inheritdoc />
94104 public override void Update ( )
95105 {
106+ if ( ! IsEnabled )
107+ {
108+ return ;
109+ }
110+
96111 // Override gaze before base.Update() updates the controllers
97112 if ( mixedRealityGazeProviderHeadOverride != null && mixedRealityGazeProviderHeadOverride . UseHeadGazeOverride && WindowsMixedRealityUtilities . SpatialCoordinateSystem != null )
98113 {
@@ -152,6 +167,10 @@ public override bool CheckCapability(MixedRealityCapability capability)
152167 return false ;
153168 }
154169
170+ #endregion IMixedRealityCapabilityCheck Implementation
171+
172+ #region Controller Utilities
173+
155174#if HP_CONTROLLER_ENABLED
156175 private MotionControllerWatcher motionControllerWatcher ;
157176
@@ -161,24 +180,11 @@ public override bool CheckCapability(MixedRealityCapability capability)
161180 private readonly Dictionary < uint , MotionControllerState > trackedMotionControllerStates = new Dictionary < uint , MotionControllerState > ( ) ;
162181
163182 private readonly Dictionary < uint , GenericXRSDKController > activeMotionControllers = new Dictionary < uint , GenericXRSDKController > ( ) ;
164- #endif
165-
166- #endregion IMixedRealityCapabilityCheck Implementation
167-
168- #region Controller Utilities
169183
170- #if HP_CONTROLLER_ENABLED
171184 private static readonly ProfilerMarker GetOrAddControllerPerfMarker = new ProfilerMarker ( "[MRTK] WindwosMixedRealityXRSDKDeviceManager.GetOrAddController" ) ;
172185
173186 protected override GenericXRSDKController GetOrAddController ( InputDevice inputDevice )
174187 {
175- #if WMR_ENABLED
176- if ( ! XRGeneralSettings . Instance . Manager . loaders . Any ( l => l is WindowsMRLoader loader && loader . displaySubsystem != null ) )
177- {
178- return null ;
179- }
180- #endif
181-
182188 using ( GetOrAddControllerPerfMarker . Auto ( ) )
183189 {
184190 GenericXRSDKController detectedController = base . GetOrAddController ( inputDevice ) ;
@@ -228,39 +234,29 @@ private void RemoveTrackedMotionController(object sender, MotionController motio
228234 }
229235 }
230236 }
231- #endif
232237
233- #if HP_CONTROLLER_ENABLED
234- // Creates a unique key for the controller based on it's vendor ID, product ID, version number, and handedness
238+ // Creates a unique key for the controller based on its vendor ID, product ID, version number, and handedness
235239 private uint GetControllerId ( uint handedness )
236240 {
237241 return handedness ;
238242 }
239243
240- #if HP_CONTROLLER_ENABLED
241244 private uint GetControllerId ( MotionController mc )
242245 {
243- var handedness = ( ( uint ) ( mc . Handedness == MotionControllerHandedness . Right ? 2 : ( mc . Handedness == MotionControllerHandedness . Left ? 1 : 0 ) ) ) ;
246+ var handedness = ( uint ) ( mc . Handedness == MotionControllerHandedness . Right ? 2 : ( mc . Handedness == MotionControllerHandedness . Left ? 1 : 0 ) ) ;
244247 return GetControllerId ( handedness ) ;
245248 }
246- #endif
247249
248250 private uint GetControllerId ( InputDevice inputDevice )
249251 {
250- var handedness = ( ( uint ) ( inputDevice . characteristics . HasFlag ( InputDeviceCharacteristics . Right ) ? 2 : inputDevice . characteristics . HasFlag ( InputDeviceCharacteristics . Left ) ? 1 : 0 ) ) ;
252+ var handedness = ( uint ) ( inputDevice . characteristics . HasFlag ( InputDeviceCharacteristics . Right ) ? 2 : ( inputDevice . characteristics . HasFlag ( InputDeviceCharacteristics . Left ) ? 1 : 0 ) ) ;
251253 return GetControllerId ( handedness ) ;
252254 }
253- #endif
255+ #endif // HP_CONTROLLER_ENABLED
254256
255257 /// <inheritdoc />
256258 protected override Type GetControllerType ( SupportedControllerType supportedControllerType )
257259 {
258- #if WMR_ENABLED
259- if ( ! XRGeneralSettings . Instance . Manager . loaders . Any ( l => l is WindowsMRLoader loader && loader . displaySubsystem != null ) )
260- {
261- return null ;
262- }
263- #endif
264260 switch ( supportedControllerType )
265261 {
266262 case SupportedControllerType . WindowsMixedReality :
0 commit comments