Skip to content

Commit a0a5e15

Browse files
committed
Check active XRSDK providers
1 parent 8427ef0 commit a0a5e15

File tree

5 files changed

+168
-32
lines changed

5 files changed

+168
-32
lines changed

Assets/MRTK/Core/Inspectors/MRTK.Inspectors.asmdef

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77
"Microsoft.MixedReality.Toolkit.Editor.ClassExtensions",
88
"Microsoft.MixedReality.Toolkit.Editor.Utilities",
99
"Unity.TextMeshPro.Editor",
10-
"Unity.TextMeshPro"
10+
"Unity.TextMeshPro",
11+
"Unity.XR.Management",
12+
"Unity.XR.Management.Editor"
1113
],
1214
"optionalUnityReferences": [],
1315
"includePlatforms": [
@@ -18,5 +20,13 @@
1820
"overrideReferences": false,
1921
"precompiledReferences": [],
2022
"autoReferenced": true,
21-
"defineConstraints": []
23+
"defineConstraints": [],
24+
"versionDefines": [
25+
{
26+
"name": "com.microsoft.mixedreality.openxr",
27+
"expression": "",
28+
"define": "MSFT_OPENXR"
29+
}
30+
],
31+
"noEngineReferences": false
2232
}

Assets/MRTK/Core/Inspectors/Setup/XRPipelineConfigWindow.cs

Lines changed: 62 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using System.Linq;
66
using TMPro;
77
using UnityEditor;
8+
using UnityEditor.Compilation;
89
using UnityEditor.PackageManager;
910
using UnityEngine;
1011

@@ -33,6 +34,17 @@ private static ConfigurationStage currentStage
3334
private void OnEnable()
3435
{
3536
Instance = this;
37+
38+
CompilationPipeline.compilationStarted += CompilationPipeline_compilationStarted;
39+
MixedRealityProjectConfigurator.SelectedSpatializer = SpatializerUtilities.CurrentSpatializer;
40+
}
41+
42+
private void CompilationPipeline_compilationStarted(object obj)
43+
{
44+
// There should be only one pop-up window which is generally tracked by IsOpen
45+
// However, when recompiling, Unity will call OnDestroy for this window but not actually destroy the editor window
46+
// This ensure we have a clean close on recompiles when this EditorWindow was open beforehand
47+
//Close();
3648
}
3749

3850
[MenuItem("Ut/Configure Demo", false, 499)]
@@ -55,10 +67,14 @@ public static void ShowWindow()
5567
private void OnGUI()
5668
{
5769
MixedRealityInspectorUtility.RenderMixedRealityToolkitLogo();
58-
EditorGUILayout.LabelField("Welcome to MRTK!", MixedRealityStylesUtility.BoldLargeTitleStyle);
59-
EditorGUILayout.Space(5);
60-
EditorGUILayout.LabelField("This configurator will go through some settings to make sure the project is ready for MRTK.");
61-
EditorGUILayout.Space(20);
70+
if (currentStage != ConfigurationStage.Done)
71+
{
72+
EditorGUILayout.LabelField("Welcome to MRTK!", MixedRealityStylesUtility.BoldLargeTitleStyle);
73+
EditorGUILayout.Space(5);
74+
EditorGUILayout.LabelField("This configurator will go through some settings to make sure the project is ready for MRTK.");
75+
EditorGUILayout.Space(20);
76+
}
77+
6278

6379
switch (currentStage)
6480
{
@@ -78,19 +94,9 @@ private void OnGUI()
7894
RenderProjectConfigurations();
7995
break;
8096
case ConfigurationStage.ImportTMP:
81-
if (TMPEssentialsImported())
82-
{
83-
currentStage = ConfigurationStage.ShowExamples;
84-
Repaint();
85-
}
8697
RenderImportTMP();
8798
break;
8899
case ConfigurationStage.ShowExamples:
89-
if (!MRTKExamplesPackageImportedViaUPM())
90-
{
91-
currentStage = ConfigurationStage.Done;
92-
Repaint();
93-
}
94100
RenderShowUPMExamples();
95101
break;
96102
case ConfigurationStage.Done:
@@ -143,7 +149,11 @@ private void RenderNoPipeline()
143149
#if UNITY_2019_3_OR_NEWER
144150
if (GUILayout.Button("XR SDK/XR Management (Recommended)"))
145151
{
152+
#if UNITY_2020_2_OR_NEWER
146153
currentStage = ConfigurationStage.SelectXRSDKPlugin;
154+
#else
155+
currentStage = ConfigurationStage.InstallBuiltinPlugin;
156+
#endif
147157
Repaint();
148158
}
149159
#endif
@@ -227,6 +237,11 @@ private void RenderXRSDKBuiltinPluginPipelineDetected()
227237

228238
private void RenderSelectXRSDKPlugin()
229239
{
240+
if (XRSettingsUtilities.XRSDKEnabled)
241+
{
242+
currentStage = ConfigurationStage.Init;
243+
Repaint();
244+
}
230245
EditorGUILayout.LabelField("Enabling the XR SDK Pipeline", EditorStyles.boldLabel);
231246
//EditorGUILayout.Space();
232247
EditorGUILayout.LabelField("There are several provider plugins for the XR SDK pipeline available in this Unity version. "
@@ -278,8 +293,15 @@ private void RenderEnableXRSDKBuiltinPlugin()
278293
{
279294
if (GUILayout.Button("Show Settings"))
280295
{
281-
//SettingsService.OpenProjectSettings("Project/XR Plug-in Management");
282-
SettingsService.OpenProjectSettings("Project/XR Plugin Management");
296+
297+
if (XRSettingsUtilities.XRManagementPresent)
298+
{
299+
SettingsService.OpenProjectSettings("Project/XR Plug-in Management");
300+
}
301+
else
302+
{
303+
SettingsService.OpenProjectSettings("Project/XR Plugin Management");
304+
}
283305
}
284306
if (GUILayout.Button("Learn more"))
285307
{
@@ -294,6 +316,11 @@ private void RenderEnableXRSDKBuiltinPlugin()
294316

295317
private void RenderEnableMicrosoftOpenXRPlugin()
296318
{
319+
if (XRSettingsUtilities.MicrosoftOpenXREnabled)
320+
{
321+
currentStage = ConfigurationStage.Init;
322+
Repaint();
323+
}
297324
EditorGUILayout.LabelField("Enabling the XR SDK Pipeline with OpenXR", EditorStyles.boldLabel);
298325
//EditorGUILayout.Space();
299326
EditorGUILayout.LabelField("To use OpenXR with the XR SDK pipeline, first press the Download Tool button. "
@@ -368,6 +395,11 @@ private void RenderChoiceDialog(MixedRealityProjectConfiguratorWindow window)
368395

369396
private void RenderImportTMP()
370397
{
398+
if (TMPEssentialsImported())
399+
{
400+
currentStage = ConfigurationStage.ShowExamples;
401+
Repaint();
402+
}
371403
EditorGUILayout.LabelField("Importing TMP Essentials", EditorStyles.boldLabel);
372404
//EditorGUILayout.Space();
373405
EditorGUILayout.LabelField("MRTK contains components that depend on TextMeshPro. It is recommended that you import TMP by clicking the Import TMP Essentials button below. "
@@ -387,6 +419,11 @@ private void RenderImportTMP()
387419

388420
private void RenderShowUPMExamples()
389421
{
422+
if (!MRTKExamplesPackageImportedViaUPM())
423+
{
424+
currentStage = ConfigurationStage.Done;
425+
Repaint();
426+
}
390427
EditorGUILayout.LabelField("Locating MRTK Examples", EditorStyles.boldLabel);
391428
//EditorGUILayout.Space();
392429
EditorGUILayout.LabelField("The MRTK Examples package includes samples to help you familiarize yourself with many core features. "
@@ -413,6 +450,15 @@ private void RenderShowUPMExamples()
413450

414451
private void RenderConfigurationCompleted()
415452
{
453+
EditorGUILayout.LabelField("MRTK Setup Completed!", MixedRealityStylesUtility.BoldLargeTitleStyle);
454+
EditorGUILayout.Space(5);
455+
EditorGUILayout.LabelField("You have finished setting up the project for Mixed Reality Toolkit. You may go through this process again by clicking Mixed Reality Toolkit on the editor menu bar -> Ultilities -> Config."
456+
+ $"\nIf there are certain settings not set according to the recommendation you may see this configurator popping up again. You may use the Ignore or Later button to suppress the behavior. "
457+
+ "We hope you enjoy using MRTK. Please find the links to our documentation and API references below. If you encountered something looking like a bug please report by opening an issue in our repository. "
458+
+ "\nThese links are accessible through Mixed Reality Toolkit on the editor menu bar -> Help "
459+
+ $"After finishing the process in the feature tool come back here to verify whether the installation is successful. A new page should be shown if you succeeded."
460+
+ $"\n\nMore information can be found at {MRFTDocsUrl}.", EditorStyles.wordWrappedLabel);
461+
EditorGUILayout.Space(20);
416462
EditorGUILayout.LabelField("Enabling the XR SDK Pipeline with OpenXR", EditorStyles.boldLabel);
417463
//EditorGUILayout.Space();
418464
EditorGUILayout.LabelField("To use OpenXR with the XR SDK pipeline, first press the Download Tool button. "

Assets/MRTK/Core/Utilities/Editor/MRTK.Editor.Utilities.asmdef

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
"references": [
44
"Unity.TextMeshPro.Editor",
55
"Unity.TextMeshPro",
6-
"Microsoft.MixedReality.Toolkit.Editor.ClassExtensions"
6+
"Microsoft.MixedReality.Toolkit.Editor.ClassExtensions",
7+
"Unity.XR.Management",
8+
"Unity.XR.Management.Editor"
79
],
810
"optionalUnityReferences": [],
911
"includePlatforms": [
@@ -14,5 +16,18 @@
1416
"overrideReferences": false,
1517
"precompiledReferences": [],
1618
"autoReferenced": true,
17-
"defineConstraints": []
19+
"defineConstraints": [],
20+
"versionDefines": [
21+
{
22+
"name": "com.microsoft.mixedreality.openxr",
23+
"expression": "",
24+
"define": "MSFT_OPENXR"
25+
},
26+
{
27+
"name": "com.unity.xr.management",
28+
"expression": "",
29+
"define": "XR_MANAGEMENT_ENABLED"
30+
}
31+
],
32+
"noEngineReferences": false
1833
}

Assets/MRTK/Core/Utilities/Editor/XRSettingsUtilities.cs

Lines changed: 76 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@
77
using System.Collections.Generic;
88
using UnityEngine;
99
using UnityEngine.XR;
10+
using System.Linq;
11+
#if XR_MANAGEMENT_ENABLED
12+
using UnityEngine.XR.Management;
13+
using UnityEditor.XR.Management;
14+
#endif // XR_MANAGEMENT_ENABLED
1015
#endif // UNITY_2019_3_OR_NEWER
1116

1217
namespace Microsoft.MixedReality.Toolkit.Utilities.Editor
@@ -47,8 +52,36 @@ public static bool XRSDKEnabled
4752
{
4853
get
4954
{
50-
#if UNITY_2019_3_OR_NEWER
51-
return IsXRSDKSuppressingLegacyXR;
55+
#if UNITY_2019_3_OR_NEWER && XR_MANAGEMENT_ENABLED
56+
if (MicrosoftOpenXREnabled)
57+
{
58+
return true;
59+
}
60+
else if (XRSDKLoadersOfCurrentBuildTarget.Count == 1 && XRSDKLoadersOfCurrentBuildTarget[0].name.Contains("Open XR"))
61+
{
62+
return false;
63+
}
64+
else
65+
{
66+
return XRSDKLoadersOfCurrentBuildTarget.Count > 0;
67+
}
68+
#else
69+
return false;
70+
#endif // UNITY_2019_3_OR_NEWER && XR_MANAGEMENT_ENABLED
71+
}
72+
}
73+
74+
75+
/// <summary>
76+
/// Gets or sets the legacy virtual reality supported property in the player settings.
77+
/// </summary>
78+
/// <remarks>Returns true if legacy XR is disabled due to XR SDK in Unity 2019.3+.</remarks>
79+
public static bool MicrosoftOpenXRPresent
80+
{
81+
get
82+
{
83+
#if UNITY_2020_2_OR_NEWER && MSFT_OPENXR
84+
return true;
5285
#else
5386
return false;
5487
#endif // UNITY_2019_3_OR_NEWER
@@ -64,8 +97,8 @@ public static bool MicrosoftOpenXREnabled
6497
{
6598
get
6699
{
67-
#if UNITY_2019_3_OR_NEWER
68-
return IsXRSDKSuppressingLegacyXR;
100+
#if UNITY_2020_2_OR_NEWER && MSFT_OPENXR
101+
return XRSDKLoadersOfCurrentBuildTarget.Any(p => p.name.Contains("Open XR"));
69102
#else
70103
return false;
71104
#endif // UNITY_2019_3_OR_NEWER
@@ -88,18 +121,18 @@ public static bool LegacyXREnabled
88121
#endif // UNITY_2020_2_OR_NEWER
89122
}
90123

91-
#if !UNITY_2020_2_OR_NEWER
92124
set
93125
{
94-
// Ensure compatibility with the pre-2019.3 XR architecture for customers / platforms
95-
// with legacy requirements.
126+
#if UNITY_2020_2_OR_NEWER
127+
Debug.LogWarning("This set operation has not effect as Legacy XR has been removed in Unity 2020!");
128+
#else
96129
#pragma warning disable 0618
97130
PlayerSettings.virtualRealitySupported = value;
98131
#pragma warning restore 0618
99-
}
100132
#endif // !UNITY_2020_2_OR_NEWER
133+
}
101134
}
102-
135+
103136
/// <summary>
104137
/// Checks if an XR SDK plug-in is installed that disables legacy VR. Returns false if so.
105138
/// </summary>
@@ -117,6 +150,22 @@ public static bool IsLegacyXRAvailable
117150
}
118151
}
119152

153+
/// <summary>
154+
/// Gets or sets the legacy virtual reality supported property in the player settings.
155+
/// </summary>
156+
/// <remarks>Returns true if legacy XR is disabled due to XR SDK in Unity 2019.3+.</remarks>
157+
public static bool XRManagementPresent
158+
{
159+
get
160+
{
161+
#if XR_MANAGEMENT_ENABLED
162+
return true;
163+
#else
164+
return false;
165+
#endif // XR_MANAGEMENT_ENABLED
166+
}
167+
}
168+
120169
#if UNITY_2019_3_OR_NEWER
121170
private static bool? isXRSDKSuppressingLegacyXR = null;
122171

@@ -155,9 +204,25 @@ private static bool IsXRSDKSuppressingLegacyXR
155204
/// Called when packages are installed or uninstalled, to toggle a new check on XR SDK package installation status.
156205
/// </summary>
157206
private static void EditorApplication_projectChanged() => isXRSDKSuppressingLegacyXR = null;
207+
#if XR_MANAGEMENT_ENABLED
208+
/// <summary>
209+
/// Is either LegacyXR pipeline or XRSDK pipeline enabled?
210+
/// </summary>
211+
private static IReadOnlyList<XRLoader> XRSDKLoadersOfCurrentBuildTarget
212+
{
213+
get
214+
{
215+
BuildTargetGroup currentBuildTarget = BuildPipeline.GetBuildTargetGroup(EditorUserBuildSettings.activeBuildTarget);
216+
XRGeneralSettings settingsOfCurrentTarget = XRGeneralSettingsPerBuildTarget.XRGeneralSettingsForBuildTarget(currentBuildTarget);
217+
#pragma warning disable CS0618 // Suppressing the warning to support xr management plugin 3.x and 4.x
218+
return settingsOfCurrentTarget.AssignedSettings.loaders;
219+
#pragma warning restore CS0618
220+
}
221+
}
222+
#endif // XR_MANAGEMENT_ENABLED
158223
#endif // UNITY_2019_3_OR_NEWER
159-
160-
[System.Obsolete("Call GetDefaultMappings(Handedness) instead.")]
224+
225+
[System.Obsolete("Call IsLegacyXRAvailable instead.")]
161226
public static bool IsLegacyXRActive => IsLegacyXRAvailable;
162227
}
163228
}

Assets/MRTK/Tools/OptimizeWindow/MixedRealityOptimizeWindow.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ private void OnGUI()
146146
EditorGUILayout.HelpBox(PerformanceTargetDescriptions[(int)PerfTarget], MessageType.Info);
147147
EditorGUILayout.Space();
148148

149-
if (!XRSettingsUtilities.LegacyXREnabled)
149+
if (!XRSettingsUtilities.LegacyXREnabled && XRSettingsUtilities.IsLegacyXRAvailable)
150150
{
151151
EditorGUILayout.HelpBox("Virtual reality support is not enabled in player settings", MessageType.Error);
152152
if (GUILayout.Button("Enable Virtual Reality Support"))

0 commit comments

Comments
 (0)