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
108namespace 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