44using System . IO ;
55using UnityEngine ;
66using UnityEditor ;
7+ using UnityEditorInternal . VR ;
78
89namespace Microsoft . MixedReality . Toolkit . Core . Utilities . Editor . Setup
910{
@@ -14,7 +15,7 @@ namespace Microsoft.MixedReality.Toolkit.Core.Utilities.Editor.Setup
1415 public class EnforceEditorSettings
1516 {
1617 private const string SessionKey = "_MixedRealityToolkit_Editor_ShownSettingsPrompts" ;
17- private const string BuildTargetKey = "_MixedRealityToolkit_Editor_Settings_CurrentBuildTarget " ;
18+ private const string BuildTargetGroupKey = "_MixedRealityToolkit_Editor_Settings_CurrentBuildTargetGroup " ;
1819
1920 private static BuildTargetGroup currentBuildTargetGroup = BuildTargetGroup . Unknown ;
2021
@@ -38,9 +39,10 @@ public static string MixedRealityToolkit_RelativeFolderPath
3839
3940 static EnforceEditorSettings ( )
4041 {
42+
4143 SetIconTheme ( ) ;
4244
43- if ( ! IsNewSession ( ) )
45+ if ( ! IsNewSession )
4446 {
4547 return ;
4648 }
@@ -71,11 +73,13 @@ static EnforceEditorSettings()
7173 "Later" ) )
7274 {
7375 EditorSettings . externalVersionControl = "Visible Meta Files" ;
74- Debug . Log ( "Updated external version control mode: " + EditorSettings . externalVersionControl ) ;
76+ Debug . Log ( $ "Updated external version control mode: { EditorSettings . externalVersionControl } " ) ;
7577 refresh = true ;
7678 }
7779 }
7880
81+ refresh |= CheckVRSettings ( ) ;
82+
7983 var currentScriptingBackend = PlayerSettings . GetScriptingBackend ( EditorUserBuildSettings . selectedBuildTargetGroup ) ;
8084
8185 if ( currentScriptingBackend != ScriptingImplementation . IL2CPP )
@@ -144,28 +148,65 @@ static EnforceEditorSettings()
144148 }
145149 }
146150
147- /// <summary>
148- /// Returns true the first time it is called within this editor session, and false for all subsequent calls.
149- /// <remarks>A new session is also true if the editor build target is changed.</remarks>
150- /// </summary>
151- private static bool IsNewSession ( )
151+ private static bool CheckVRSettings ( )
152152 {
153- if ( currentBuildTargetGroup == BuildTargetGroup . Unknown )
153+ var currentBuildTarget = EditorUserBuildSettings . activeBuildTarget ;
154+ var availableVRDevices = VREditor . GetAvailableVirtualRealitySDKs ( currentBuildTargetGroup ) ;
155+ var enabledVRDevices = VREditor . GetVREnabledDevicesOnTarget ( currentBuildTarget ) ;
156+
157+ bool isVRDeviceEnabled = false ;
158+
159+ Debug . Log ( "Available Devices:" ) ;
160+ foreach ( string availableVRDevice in availableVRDevices )
154161 {
155- currentBuildTargetGroup = ( BuildTargetGroup ) SessionState . GetInt ( BuildTargetKey , ( int ) EditorUserBuildSettings . selectedBuildTargetGroup ) ;
162+ isVRDeviceEnabled |= VREditor . IsVRDeviceEnabledForBuildTarget ( currentBuildTarget , availableVRDevice ) ;
163+ Debug . Log ( availableVRDevice ) ;
156164 }
157165
158- if ( ! SessionState . GetBool ( SessionKey , false ) || currentBuildTargetGroup != EditorUserBuildSettings . selectedBuildTargetGroup )
166+ Debug . Log ( "Enabled Devices:" ) ;
167+ foreach ( var enabledVRDevice in enabledVRDevices )
159168 {
160- currentBuildTargetGroup = EditorUserBuildSettings . selectedBuildTargetGroup ;
161- SessionState . SetInt ( BuildTargetKey , ( int ) EditorUserBuildSettings . selectedBuildTargetGroup ) ;
162- SessionState . SetBool ( SessionKey , true ) ;
163- return true ;
169+ Debug . Log ( enabledVRDevice ) ;
164170 }
165171
172+ if ( ! isVRDeviceEnabled || ! PlayerSettings . virtualRealitySupported )
173+ {
174+ if ( EditorUtility . DisplayDialog ( "Activate XR Settings?" ,
175+ "The Mixed Reality Toolkit would like to enable the XR Settings for you." , "Ok" , "Later" ) )
176+ {
177+
178+ }
179+ }
180+
181+ //VREditor.SetVREnabledDevicesOnTargetGroup(BuildTargetGroup.WSA, new[] { "WindowsMR" });
166182 return false ;
167183 }
168184
185+ /// <summary>
186+ /// Returns true the first time it is called within this editor session, and false for all subsequent calls.
187+ /// <remarks>A new session is also true if the editor build target group is changed.</remarks>
188+ /// </summary>
189+ private static bool IsNewSession
190+ {
191+ get
192+ {
193+ if ( currentBuildTargetGroup == BuildTargetGroup . Unknown )
194+ {
195+ currentBuildTargetGroup = ( BuildTargetGroup ) SessionState . GetInt ( BuildTargetGroupKey , ( int ) EditorUserBuildSettings . selectedBuildTargetGroup ) ;
196+ }
197+
198+ if ( ! SessionState . GetBool ( SessionKey , false ) || currentBuildTargetGroup != EditorUserBuildSettings . selectedBuildTargetGroup )
199+ {
200+ currentBuildTargetGroup = EditorUserBuildSettings . selectedBuildTargetGroup ;
201+ SessionState . SetInt ( BuildTargetGroupKey , ( int ) EditorUserBuildSettings . selectedBuildTargetGroup ) ;
202+ SessionState . SetBool ( SessionKey , true ) ;
203+ return true ;
204+ }
205+
206+ return false ;
207+ }
208+ }
209+
169210 private static bool FindDirectory ( string directoryPathToSearch , string directoryName , out string path )
170211 {
171212 path = string . Empty ;
0 commit comments