Skip to content

Commit 41cf360

Browse files
committed
Improve XR pipeline detection to prevent regression
1 parent 687ea6b commit 41cf360

File tree

4 files changed

+30
-29
lines changed

4 files changed

+30
-29
lines changed

Assets/MRTK/Core/Definitions/MixedRealityToolkitConfigurationProfile.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ public bool IsBoundarySystemEnabled
169169
/// <summary>
170170
/// Boundary system class to instantiate at runtime.
171171
/// </summary>
172-
public SystemType BoundarySystemSystemType => (!XRSettingsUtilities.LegacyXRAvailable && xrsdkBoundarySystemType?.Type != null) ? xrsdkBoundarySystemType : boundarySystemType;
172+
public SystemType BoundarySystemSystemType => (XRSettingsUtilities.XRSDKEnabled && xrsdkBoundarySystemType?.Type != null) ? xrsdkBoundarySystemType : boundarySystemType;
173173

174174
[SerializeField]
175175
[Tooltip("Profile for wiring up boundary visualization assets.")]

Assets/MRTK/Core/MRTK.Core.asmdef

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
"name": "Microsoft.MixedReality.Toolkit",
33
"references": [
44
"Microsoft.MixedReality.Toolkit.Async",
5-
"Microsoft.MixedReality.Toolkit.Editor.Utilities"
5+
"Microsoft.MixedReality.Toolkit.Editor.Utilities",
6+
"Unity.XR.Management"
67
],
78
"includePlatforms": [],
89
"excludePlatforms": [],
@@ -16,6 +17,11 @@
1617
"name": "com.microsoft.windows.mixedreality.dotnetwinrt",
1718
"expression": "",
1819
"define": "DOTNETWINRT_PRESENT"
20+
},
21+
{
22+
"name": "com.unity.xr.management",
23+
"expression": "",
24+
"define": "XR_MANAGEMENT_ENABLED"
1925
}
2026
],
2127
"noEngineReferences": false

Assets/MRTK/Core/Services/BaseDataProviderAccessCoreSystem.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ private bool RegisterDataProviderInternal<T>(
216216
#if UNITY_2020_1_OR_NEWER
217217
SupportedUnityXRPipelines.XRSDK;
218218
#elif UNITY_2019
219-
!XRSettingsUtilities.LegacyXRAvailable ? SupportedUnityXRPipelines.XRSDK : SupportedUnityXRPipelines.LegacyXR;
219+
XRSettingsUtilities.XRSDKEnabled ? SupportedUnityXRPipelines.XRSDK : SupportedUnityXRPipelines.LegacyXR;
220220
#else
221221
SupportedUnityXRPipelines.LegacyXR;
222222
#endif

Assets/MRTK/Core/Utilities/XRSettingsUtilities.cs

Lines changed: 21 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
// Copyright (c) Microsoft Corporation.
22
// Licensed under the MIT License.
33

4-
#if UNITY_2019_3_OR_NEWER
5-
using System.Collections.Generic;
6-
using UnityEngine;
7-
using UnityEngine.XR;
8-
#endif // UNITY_2019_3_OR_NEWER
4+
#if XR_MANAGEMENT_ENABLED
5+
using UnityEngine.XR.Management;
6+
#endif // XR_MANAGEMENT_ENABLED
97

108
namespace Microsoft.MixedReality.Toolkit.Utilities
119
{
@@ -15,40 +13,37 @@ namespace Microsoft.MixedReality.Toolkit.Utilities
1513
/// </summary>
1614
public static class XRSettingsUtilities
1715
{
18-
#if UNITY_2019_3_OR_NEWER && !UNITY_2020_2_OR_NEWER
19-
private static bool? legacyXRAvailable = null;
20-
#endif // UNITY_2019_3_OR_NEWER && !UNITY_2020_2_OR_NEWER
16+
#if !UNITY_2020_2_OR_NEWER && UNITY_2019_3_OR_NEWER && XR_MANAGEMENT_ENABLED
17+
private static bool? isXRSDKEnabled = null;
18+
#endif // !UNITY_2020_2_OR_NEWER && UNITY_2019_3_OR_NEWER && XR_MANAGEMENT_ENABLED
2119

2220
/// <summary>
2321
/// Checks if an XR SDK plug-in is installed that disables legacy VR. Returns false if so.
2422
/// </summary>
25-
public static bool LegacyXRAvailable
23+
public static bool XRSDKEnabled
2624
{
2725
get
2826
{
2927
#if UNITY_2020_2_OR_NEWER
30-
return false;
31-
#elif UNITY_2019_3_OR_NEWER
32-
if (!legacyXRAvailable.HasValue)
28+
return true;
29+
#elif UNITY_2019_3_OR_NEWER && XR_MANAGEMENT_ENABLED
30+
if (!isXRSDKEnabled.HasValue)
3331
{
34-
legacyXRAvailable = true;
35-
36-
List<XRDisplaySubsystemDescriptor> descriptors = new List<XRDisplaySubsystemDescriptor>();
37-
SubsystemManager.GetSubsystemDescriptors(descriptors);
38-
39-
foreach (XRDisplaySubsystemDescriptor displayDescriptor in descriptors)
32+
XRGeneralSettings currentSettings = XRGeneralSettings.Instance;
33+
if (currentSettings != null && currentSettings.AssignedSettings != null)
4034
{
41-
if (displayDescriptor.disablesLegacyVr)
42-
{
43-
legacyXRAvailable = false;
44-
break;
45-
}
35+
#pragma warning disable CS0618 // Suppressing the warning to support xr management plugin 3.x and 4.x
36+
isXRSDKEnabled = currentSettings.AssignedSettings.loaders.Count > 0;
37+
#pragma warning restore CS0618
38+
}
39+
else
40+
{
41+
isXRSDKEnabled = false;
4642
}
4743
}
48-
49-
return legacyXRAvailable.HasValue && legacyXRAvailable.Value;
44+
return isXRSDKEnabled.Value;
5045
#else
51-
return true;
46+
return false;
5247
#endif // UNITY_2020_2_OR_NEWER
5348
}
5449
}

0 commit comments

Comments
 (0)