Skip to content

Commit 069f575

Browse files
committed
Update Oculus and WMR with IsActiveLoader pattern
1 parent 5457aec commit 069f575

File tree

3 files changed

+51
-12
lines changed

3 files changed

+51
-12
lines changed

Assets/MRTK/Providers/Oculus/XRSDK/OculusXRSDKDeviceManager.cs

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
using Microsoft.MixedReality.Toolkit.Utilities;
66
using Microsoft.MixedReality.Toolkit.XRSDK.Input;
77
using System;
8-
using System.Linq;
98
using UnityEngine.XR;
109

1110
#if OCULUSINTEGRATION_PRESENT
@@ -14,7 +13,6 @@
1413
using Unity.XR.Oculus;
1514
#endif // OCULUS_ENABLED
1615
using UnityEngine;
17-
using UnityEngine.XR.Management;
1816
#endif // OCULUSINTEGRATION_PRESENT
1917

2018
namespace Microsoft.MixedReality.Toolkit.XRSDK.Oculus.Input
@@ -140,16 +138,32 @@ protected override SupportedControllerType GetCurrentControllerType(InputDevice
140138
#endregion Controller Utilities
141139

142140
#if OCULUSINTEGRATION_PRESENT
141+
private bool? isActiveLoader = null;
142+
private bool IsActiveLoader
143+
{
144+
get
145+
{
146+
#if OCULUS_ENABLED
147+
if (!isActiveLoader.HasValue)
148+
{
149+
isActiveLoader = IsLoaderActive<OculusLoader>();
150+
}
151+
#endif // OCULUS_ENABLED
152+
153+
return isActiveLoader ?? false;
154+
}
155+
}
156+
143157
/// <inheritdoc/>
144158
public override void Enable()
145159
{
146-
base.Enable();
147-
if (!XRGeneralSettings.Instance.Manager.loaders.Any(l => l is OculusLoader loader && loader.displaySubsystem != null))
148-
160+
if (!IsActiveLoader)
149161
{
150162
return;
151163
}
152164

165+
base.Enable();
166+
153167
SetupInput();
154168
ConfigurePerformancePreferences();
155169
}
@@ -158,6 +172,11 @@ public override void Enable()
158172
/// <inheritdoc/>
159173
public override void Update()
160174
{
175+
if (!IsEnabled)
176+
{
177+
return;
178+
}
179+
161180
base.Update();
162181

163182
if (OVRPlugin.GetHandTrackingEnabled())

Assets/MRTK/Providers/WindowsMixedReality/XRSDK/MRTK.WMR.XRSDK.asmdef

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44
"Microsoft.MixedReality.Toolkit",
55
"Microsoft.MixedReality.Toolkit.Providers.WindowsMixedReality.Shared",
66
"Microsoft.MixedReality.Toolkit.Providers.XRSDK",
7-
"Unity.XR.WindowsMixedReality",
8-
"Unity.XR.Management"
7+
"Unity.XR.WindowsMixedReality"
98
],
109
"includePlatforms": [
1110
"Editor",

Assets/MRTK/Providers/WindowsMixedReality/XRSDK/WindowsMixedRealityDeviceManager.cs

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,22 @@ public WindowsMixedRealityDeviceManager(
5050
uint priority = DefaultPriority,
5151
BaseMixedRealityProfile profile = null) : base(inputSystem, name, priority, profile) { }
5252

53+
#if WMR_ENABLED
54+
private bool? isActiveLoader = null;
55+
private bool IsActiveLoader
56+
{
57+
get
58+
{
59+
if (!isActiveLoader.HasValue)
60+
{
61+
isActiveLoader = IsLoaderActive("WindowsMRLoader");
62+
}
63+
64+
return isActiveLoader ?? false;
65+
}
66+
}
67+
#endif // WMR_ENABLED
68+
5369
#region IMixedRealityDeviceManager Interface
5470

5571
#if (UNITY_WSA && DOTNETWINRT_PRESENT) || WINDOWS_UWP
@@ -58,15 +74,15 @@ public WindowsMixedRealityDeviceManager(
5874
/// <inheritdoc />
5975
public override void Enable()
6076
{
61-
base.Enable();
62-
6377
#if WMR_ENABLED
64-
if (!XRGeneralSettings.Instance.Manager.loaders.Any(l => l is WindowsMRLoader loader && loader.displaySubsystem != null))
78+
if (!IsActiveLoader)
6579
{
6680
return;
6781
}
6882
#endif // WMR_ENABLED
6983

84+
base.Enable();
85+
7086
if (WindowsMixedRealityUtilities.UtilitiesProvider == null)
7187
{
7288
WindowsMixedRealityUtilities.UtilitiesProvider = new XRSDKWindowsMixedRealityUtilitiesProvider();
@@ -86,6 +102,11 @@ public override void Enable()
86102
/// <inheritdoc />
87103
public override void Update()
88104
{
105+
if (!IsEnabled)
106+
{
107+
return;
108+
}
109+
89110
// Override gaze before base.Update() updates the controllers
90111
if (mixedRealityGazeProviderHeadOverride != null && mixedRealityGazeProviderHeadOverride.UseHeadGazeOverride && WindowsMixedRealityUtilities.SpatialCoordinateSystem != null)
91112
{
@@ -166,7 +187,7 @@ public override bool CheckCapability(MixedRealityCapability capability)
166187
protected override GenericXRSDKController GetOrAddController(InputDevice inputDevice)
167188
{
168189
#if WMR_ENABLED
169-
if (!XRGeneralSettings.Instance.Manager.loaders.Any(l => l is WindowsMRLoader loader && loader.displaySubsystem != null))
190+
if (!IsActiveLoader)
170191
{
171192
return null;
172193
}
@@ -245,7 +266,7 @@ private uint GetControllerId(InputDevice inputDevice)
245266
protected override Type GetControllerType(SupportedControllerType supportedControllerType)
246267
{
247268
#if WMR_ENABLED
248-
if (!XRGeneralSettings.Instance.Manager.loaders.Any(l => l is WindowsMRLoader loader && loader.displaySubsystem != null))
269+
if (!IsActiveLoader)
249270
{
250271
return null;
251272
}

0 commit comments

Comments
 (0)