44using System . IO ;
55using UnityEngine ;
66using UnityEditor ;
7+ using UnityEditor . Build ;
78
89namespace Microsoft . MixedReality . Toolkit . Core . Utilities . Editor . Setup
910{
1011 /// <summary>
1112 /// Sets Force Text Serialization and visible meta files in all projects that use the Mixed Reality Toolkit.
1213 /// </summary>
1314 [ InitializeOnLoad ]
14- public class MixedRealityEditorSettings
15+ public class MixedRealityEditorSettings : IActiveBuildTargetChanged
1516 {
1617 private const string SessionKey = "_MixedRealityToolkit_Editor_ShownSettingsPrompts" ;
17- private const string BuildTargetKey = "_MixedRealityToolkit_Editor_Settings_CurrentBuildTarget" ;
18-
19- private static BuildTargetGroup currentBuildTargetGroup = BuildTargetGroup . Unknown ;
2018
2119 private static string mixedRealityToolkit_RelativeFolderPath = string . Empty ;
2220
@@ -42,96 +40,42 @@ static MixedRealityEditorSettings()
4240 {
4341 SetIconTheme ( ) ;
4442
45- if ( ! IsNewSession ( ) )
43+ if ( ! IsNewSession )
4644 {
4745 return ;
4846 }
4947
5048 bool refresh = false ;
5149 bool restart = false ;
5250
53- if ( EditorSettings . serializationMode != SerializationMode . ForceText )
51+ if ( EditorSettings . serializationMode != SerializationMode . ForceText ||
52+ PlayerSettings . GetScriptingBackend ( EditorUserBuildSettings . selectedBuildTargetGroup ) != ScriptingImplementation . IL2CPP ||
53+ ! EditorSettings . externalVersionControl . Equals ( "Visible Meta Files" ) ||
54+ ! PlayerSettings . virtualRealitySupported )
5455 {
5556 if ( EditorUtility . DisplayDialog (
56- "Force Text Asset Serialization?" ,
57- "The Mixed Reality Toolkit is easier to maintain if the asset serialization mode for this project is set to \" Force Text\" . Would you like to make this change?" ,
58- "Force Text Serialization" ,
57+ "Apply Mixed Reality Toolkit Default Settings?" ,
58+ "The Mixed Reality Toolkit needs to apply the following settings to your project:\n \n " +
59+ "- Enable XR Settings for your current platform\n " +
60+ "- Force Text Serialization\n " +
61+ "- Visible meta files\n " +
62+ "- Change the Scripting Backend to use IL2CPP\n \n " +
63+ "Would you like to make this change?" ,
64+ "Apply" ,
5965 "Later" ) )
6066 {
6167 EditorSettings . serializationMode = SerializationMode . ForceText ;
62- Debug . Log ( "Setting Force Text Serialization" ) ;
63- refresh = true ;
64- }
65- }
66-
67- if ( ! EditorSettings . externalVersionControl . Equals ( "Visible Meta Files" ) )
68- {
69- if ( EditorUtility . DisplayDialog (
70- "Make Meta Files Visible?" ,
71- "The Mixed Reality Toolkit would like to make meta files visible so they can be more easily handled with common version control systems. Would you like to make this change?" ,
72- "Enable Visible Meta Files" ,
73- "Later" ) )
74- {
7568 EditorSettings . externalVersionControl = "Visible Meta Files" ;
76- Debug . Log ( "Updated external version control mode: " + EditorSettings . externalVersionControl ) ;
77- refresh = true ;
78- }
79- }
80-
81- var currentScriptingBackend = PlayerSettings . GetScriptingBackend ( EditorUserBuildSettings . selectedBuildTargetGroup ) ;
82-
83- if ( currentScriptingBackend != ScriptingImplementation . IL2CPP )
84- {
85- if ( EditorUtility . DisplayDialog (
86- "Change the Scripting Backend to IL2CPP?" ,
87- "The Mixed Reality Toolkit would like to change the Scripting Backend to use IL2CPP.\n \n " +
88- "Would you like to make this change?" ,
89- "Enable IL2CPP" ,
90- "Later" ) )
91- {
9269 PlayerSettings . SetScriptingBackend ( EditorUserBuildSettings . selectedBuildTargetGroup , ScriptingImplementation . IL2CPP ) ;
93- Debug . Log ( "Updated Scripting Backend to use IL2CPP" ) ;
70+ PlayerSettings . virtualRealitySupported = true ;
9471 refresh = true ;
9572 }
9673 }
9774
9875 if ( PlayerSettings . scriptingRuntimeVersion != ScriptingRuntimeVersion . Latest )
9976 {
100- if ( EditorUtility . DisplayDialog (
101- "Change the Scripting Runtime Version to the 4.x Equivalent?" ,
102- "The Mixed Reality Toolkit would like to change the Scripting Runtime Version to use the .NET 4.x Equivalent.\n \n " +
103- "In order for the change to take place the Editor must be restarted, and any changes will be saved.\n \n " +
104- "WARNING: If you do not make this change, then your project will fail to compile.\n \n " +
105- "Would you like to make this change?" ,
106- "Enable .NET 4.x Equivalent" ,
107- "Later" ) )
108- {
109- PlayerSettings . scriptingRuntimeVersion = ScriptingRuntimeVersion . Latest ;
110- restart = true ;
111- }
112- else
113- {
114- Debug . LogWarning ( "You must change the Runtime Scripting Version to 4.x in the Player Settings to get this asset to compile correctly." ) ;
115- }
116- }
117-
118- if ( PlayerSettings . scriptingRuntimeVersion == ScriptingRuntimeVersion . Latest )
119- {
120- var currentApiCompatibility = PlayerSettings . GetApiCompatibilityLevel ( EditorUserBuildSettings . selectedBuildTargetGroup ) ;
121- if ( currentApiCompatibility != ApiCompatibilityLevel . NET_4_6 && currentApiCompatibility != ApiCompatibilityLevel . NET_Standard_2_0 )
122- {
123- if ( EditorUtility . DisplayDialog (
124- "Change the Scripting API Compatibility to .NET 4.x?" ,
125- "The Mixed Reality Toolkit would like to change the Scripting API Compatibility to use .NET 4.x\n \n " +
126- "Would you like to make this change?" ,
127- "Enable .NET 4.x" ,
128- "Later" ) )
129- {
130- PlayerSettings . SetApiCompatibilityLevel ( EditorUserBuildSettings . selectedBuildTargetGroup , ApiCompatibilityLevel . NET_4_6 ) ;
131- Debug . Log ( "Updated Scripting API Compatibility to .NET 4.x" ) ;
132- refresh = true ;
133- }
134- }
77+ PlayerSettings . scriptingRuntimeVersion = ScriptingRuntimeVersion . Latest ;
78+ restart = true ;
13579 }
13680
13781 if ( refresh || restart )
@@ -148,24 +92,17 @@ static MixedRealityEditorSettings()
14892
14993 /// <summary>
15094 /// Returns true the first time it is called within this editor session, and false for all subsequent calls.
151- /// <remarks>A new session is also true if the editor build target is changed.</remarks>
95+ /// <remarks>A new session is also true if the editor build target group is changed.</remarks>
15296 /// </summary>
153- private static bool IsNewSession ( )
97+ private static bool IsNewSession
15498 {
155- if ( currentBuildTargetGroup == BuildTargetGroup . Unknown )
99+ get
156100 {
157- currentBuildTargetGroup = ( BuildTargetGroup ) SessionState . GetInt ( BuildTargetKey , ( int ) EditorUserBuildSettings . selectedBuildTargetGroup ) ;
158- }
101+ if ( SessionState . GetBool ( SessionKey , false ) ) { return false ; }
159102
160- if ( ! SessionState . GetBool ( SessionKey , false ) || currentBuildTargetGroup != EditorUserBuildSettings . selectedBuildTargetGroup )
161- {
162- currentBuildTargetGroup = EditorUserBuildSettings . selectedBuildTargetGroup ;
163- SessionState . SetInt ( BuildTargetKey , ( int ) EditorUserBuildSettings . selectedBuildTargetGroup ) ;
164103 SessionState . SetBool ( SessionKey , true ) ;
165104 return true ;
166105 }
167-
168- return false ;
169106 }
170107
171108 private static bool FindDirectory ( string directoryPathToSearch , string directoryName , out string path )
@@ -227,5 +164,12 @@ private static void SetIconTheme()
227164 AssetDatabase . SaveAssets ( ) ;
228165 AssetDatabase . Refresh ( ImportAssetOptions . ForceUpdate ) ;
229166 }
167+
168+ public int callbackOrder { get ; } = 0 ;
169+
170+ public void OnActiveBuildTargetChanged ( BuildTarget previousTarget , BuildTarget newTarget )
171+ {
172+ SessionState . SetBool ( SessionKey , false ) ;
173+ }
230174 }
231175}
0 commit comments