Skip to content

Commit a4a93a8

Browse files
authored
CU-868gjncm9: Add violations for Mock HMD Loader (#28)
I ended up adding the mock hmd package as a dependency because I also need API access to it and the XR management plugin that it depends on and comes along with it. We can also add the packages using the "Auto Resolve" button provided: * We add the correct package version based on the Unity editor. This isn't too much, especially because mock-hmd 1.3.1 works with a wide range of editors * More importantly, adding these packages via the export window means our SDK code cannot reference the APIs we need to 1) Ensure Mock HMD loader is active 2) Stereo mode is multipass
2 parents 646d505 + d6eac25 commit a4a93a8

File tree

8 files changed

+145
-12
lines changed

8 files changed

+145
-12
lines changed

Assets/MXRUS/Editor/MXRUS.Editor.asmdef

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
{
22
"name": "MXRUS.Editor",
3+
"rootNamespace": "",
34
"references": [
4-
"GUID:0a6056b72db1f26499a3860e9a71e042",
5-
"GUID:1af6960767f2322479cb09771bdaefa6"
5+
"MXRUS.Runtime",
6+
"MXRUS.Embeddings",
7+
"Unity.XR.MockHMD",
8+
"Unity.XR.Management",
9+
"Unity.XR.Management.Editor"
610
],
711
"includePlatforms": [
812
"Editor"

Assets/MXRUS/Editor/SceneExportValidator.cs

Lines changed: 66 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
using UnityEngine.EventSystems;
77
using UnityEngine.SceneManagement;
88
using UnityEngine.Rendering;
9+
using Unity.XR.MockHMD;
10+
using UnityEditor.XR.Management;
11+
using UnityEditor.XR.Management.Metadata;
912

1013
namespace MXRUS.SDK.Editor {
1114
internal class SceneExportValidator : ISceneExportValidator {
@@ -19,6 +22,14 @@ public List<SceneExportViolation> Validate() {
1922
if (renderPipelineViolation != null)
2023
violations.Add(renderPipelineViolation);
2124

25+
var mockHMDDisabledViolation = GetMockHMDDisabledViolation();
26+
if (mockHMDDisabledViolation != null)
27+
violations.Add(mockHMDDisabledViolation);
28+
29+
var mockHMDRenderModeViolation = GetMockHMDRenderModeViolation();
30+
if (mockHMDRenderModeViolation != null)
31+
violations.Add(mockHMDRenderModeViolation);
32+
2233
violations.AddRange(GetShaderViolations());
2334
violations.AddRange(GetScriptViolations());
2435
violations.AddRange(GetCameraViolations());
@@ -38,7 +49,6 @@ public List<SceneExportViolation> Validate() {
3849
return violations;
3950
}
4051

41-
4252
/// <summary>
4353
/// Checks and ensures the project not configured to use a render pipeline other than Universal Render Pipeline
4454
/// </summary>
@@ -56,6 +66,59 @@ private SceneExportViolation GetRenderPipelineViolation() {
5666
return violation;
5767
}
5868

69+
70+
private SceneExportViolation GetMockHMDDisabledViolation() {
71+
string loaderName = "MockHMDLoader";
72+
73+
if (!EditorBuildSettings.TryGetConfigObject("com.unity.xr.management.loader_settings",
74+
out XRGeneralSettingsPerBuildTarget buildTargetSettings)) {
75+
return null;
76+
}
77+
78+
var settings = buildTargetSettings.SettingsForBuildTarget(BuildTargetGroup.Android);
79+
if (settings == null || settings.Manager == null) {
80+
return null;
81+
}
82+
83+
var activeLoaderNames = settings.Manager.activeLoaders
84+
.Select(x => x.GetType().Name)
85+
.ToList();
86+
87+
if (activeLoaderNames.Contains(loaderName)) {
88+
return null;
89+
}
90+
91+
return new SceneExportViolation(
92+
SceneExportViolation.Types.MockHMDLoaderNotActive,
93+
true,
94+
"Mock HMD Loader is not active in XR Plug-In Management"
95+
).SetAutoResolver("This will active the Mock HMD Loader.", x => {
96+
EditorUtility.SetDirty(settings);
97+
XRPackageMetadataStore.AssignLoader(settings.Manager, loaderName, BuildTargetGroup.Android);
98+
AssetDatabase.SaveAssets();
99+
});
100+
}
101+
102+
/// <summary>
103+
/// Checks if the Mock HMD Loader has render mode set to multipass
104+
/// </summary>
105+
/// <returns></returns>
106+
private SceneExportViolation GetMockHMDRenderModeViolation() {
107+
var instance = MockHMDBuildSettings.Instance;
108+
if (instance.renderMode == MockHMDBuildSettings.RenderMode.MultiPass) {
109+
return null;
110+
}
111+
112+
return new SceneExportViolation(
113+
SceneExportViolation.Types.MockHMDLoaderRenderModeNotMultiPass,
114+
true,
115+
"Mock HMD XR Loader render mode is not set to multipass"
116+
).SetAutoResolver("Set Render Mode to Multi Pass", x => {
117+
instance.renderMode = MockHMDBuildSettings.RenderMode.MultiPass;
118+
AssetDatabase.SaveAssets();
119+
});
120+
}
121+
59122
/// <summary>
60123
/// Checks and ensures the scene doesn't have materials that use unsupported shaders.
61124
/// Only shaders in the following namespaces/family are supported:
@@ -251,9 +314,9 @@ private SceneExportViolation GetSceneNameViolation() {
251314
};
252315

253316
var activeScene = SceneManager.GetActiveScene();
254-
if(reservedNames.Contains(activeScene.name)) {
317+
if (reservedNames.Contains(activeScene.name)) {
255318
return new SceneExportViolation(
256-
SceneExportViolation.Types.SceneNameViolation,
319+
SceneExportViolation.Types.DisallowedSceneName,
257320
true,
258321
$"The scene name not allowed. The following names are prohibited: {string.Join(", ", reservedNames)}"
259322
);

Assets/MXRUS/Editor/SceneExportViolation.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,17 @@ public enum Types {
6363
/// <summary>
6464
/// Whether the scene name is allowed.
6565
/// </summary>
66-
SceneNameViolation
66+
DisallowedSceneName,
67+
68+
/// <summary>
69+
/// Whether the Mock HMD Loader is active
70+
/// </summary>
71+
MockHMDLoaderNotActive,
72+
73+
/// <summary>
74+
/// Whether the Mock HMD Loader render pass is multipass
75+
/// </summary>
76+
MockHMDLoaderRenderModeNotMultiPass
6777
}
6878

6979
/// <summary>

Assets/MXRUS/Editor/SceneExportWindow.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@ private void OnGUI_DisplayExportWizard() {
179179
}
180180

181181
private void Validate() {
182+
AssetDatabase.SaveAssets();
182183
_violations = new SceneExportValidator().Validate();
183184
_violationTypes = _violations.Select(x => x.Type).Distinct().ToList();
184185
_foldoutStates = _violationTypes.Select(x => false).ToList();

Assets/MXRUS/Runtime/MXRUS.Runtime.asmdef

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
{
22
"name": "MXRUS.Runtime",
3-
"references": [
4-
"GUID:f51ebe6a0ceec4240a699833d6309b23"
5-
],
3+
"rootNamespace": "",
4+
"references": [],
65
"includePlatforms": [],
76
"excludePlatforms": [],
87
"allowUnsafeCode": false,

Assets/MXRUS/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "com.mxr.mxrus.sdk",
3-
"version": "0.3.0",
3+
"version": "0.4.0",
44
"displayName": "ManageXR Unity Scene SDK",
55
"description": "Tools for creating and loading 3D environments for ManageXR Home Screen in mxrus format.",
66
"unity": "2019.4",
@@ -10,6 +10,7 @@
1010
"url": "https://www.managexr.com"
1111
},
1212
"dependencies": {
13-
"com.unity.sharp-zip-lib": "1.3.8"
13+
"com.unity.sharp-zip-lib": "1.3.8",
14+
"com.unity.xr.mock-hmd": "1.3.1-preview.1"
1415
}
1516
}

Packages/manifest.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
{
22
"dependencies": {
3-
"com.unity.sharp-zip-lib": "1.3.8",
43
"com.unity.ide.rider": "1.2.1",
54
"com.unity.ide.visualstudio": "2.0.15",
65
"com.unity.ide.vscode": "1.2.5",
6+
"com.unity.sharp-zip-lib": "1.3.8",
77
"com.unity.test-framework": "1.1.31",
88
"com.unity.textmeshpro": "2.1.6",
99
"com.unity.timeline": "1.2.18",
1010
"com.unity.ugui": "1.0.0",
11+
"com.unity.xr.management": "4.5.1",
12+
"com.unity.xr.mock-hmd": "1.3.1-preview.1",
1113
"com.unity.modules.ai": "1.0.0",
1214
"com.unity.modules.androidjni": "1.0.0",
1315
"com.unity.modules.animation": "1.0.0",

Packages/packages-lock.json

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,47 @@
8080
"com.unity.modules.imgui": "1.0.0"
8181
}
8282
},
83+
"com.unity.xr.core-utils": {
84+
"version": "2.2.1",
85+
"depth": 1,
86+
"source": "registry",
87+
"dependencies": {
88+
"com.unity.modules.xr": "1.0.0"
89+
},
90+
"url": "https://packages.unity.com"
91+
},
92+
"com.unity.xr.legacyinputhelpers": {
93+
"version": "2.1.11",
94+
"depth": 1,
95+
"source": "registry",
96+
"dependencies": {
97+
"com.unity.modules.vr": "1.0.0",
98+
"com.unity.modules.xr": "1.0.0"
99+
},
100+
"url": "https://packages.unity.com"
101+
},
102+
"com.unity.xr.management": {
103+
"version": "4.5.1",
104+
"depth": 0,
105+
"source": "registry",
106+
"dependencies": {
107+
"com.unity.modules.vr": "1.0.0",
108+
"com.unity.modules.xr": "1.0.0",
109+
"com.unity.xr.core-utils": "2.2.1",
110+
"com.unity.modules.subsystems": "1.0.0",
111+
"com.unity.xr.legacyinputhelpers": "2.1.11"
112+
},
113+
"url": "https://packages.unity.com"
114+
},
115+
"com.unity.xr.mock-hmd": {
116+
"version": "1.3.1-preview.1",
117+
"depth": 0,
118+
"source": "registry",
119+
"dependencies": {
120+
"com.unity.xr.management": "4.0.1"
121+
},
122+
"url": "https://packages.unity.com"
123+
},
83124
"com.unity.modules.ai": {
84125
"version": "1.0.0",
85126
"depth": 0,
@@ -213,6 +254,18 @@
213254
"depth": 0,
214255
"source": "builtin",
215256
"dependencies": {
257+
"com.unity.modules.ui": "1.0.0",
258+
"com.unity.modules.imgui": "1.0.0",
259+
"com.unity.modules.jsonserialize": "1.0.0",
260+
"com.unity.modules.uielementsnative": "1.0.0"
261+
}
262+
},
263+
"com.unity.modules.uielementsnative": {
264+
"version": "1.0.0",
265+
"depth": 1,
266+
"source": "builtin",
267+
"dependencies": {
268+
"com.unity.modules.ui": "1.0.0",
216269
"com.unity.modules.imgui": "1.0.0",
217270
"com.unity.modules.jsonserialize": "1.0.0"
218271
}

0 commit comments

Comments
 (0)