66using UnityEngine . EventSystems ;
77using UnityEngine . SceneManagement ;
88using UnityEngine . Rendering ;
9+ using Unity . XR . MockHMD ;
10+ using UnityEditor . XR . Management ;
11+ using UnityEditor . XR . Management . Metadata ;
912
1013namespace 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 ) ;
0 commit comments