@@ -15,7 +15,7 @@ public class InitializeProject : EditorWindow
1515 static readonly string id = "InitializeProject_" ;
1616
1717 // settings
18- static string [ ] folders = new string [ ] { "Fonts" , "Materials" , "Models" , "Plugins" , " Prefabs", "Scenes" , "Scripts" , "Shaders" , "Sounds" , "Textures" } ;
18+ static string [ ] folders = new string [ ] { "Fonts" , "Materials" , "Models" , "Prefabs" , "Scenes" , "Scripts" , "Shaders" , "Sounds" , "Textures" } ;
1919
2020 static Dictionary < string , string > addPackages = new Dictionary < string , string > ( ) { { "com.unity.ide.visualstudio" , "2.0.22" } } ;
2121 static string [ ] blackListedPackages = new string [ ] { "com.unity.modules.unityanalytics" , "com.unity.modules.director" , "com.unity.collab-proxy" , "com.unity.ide.rider" , "com.unity.ide.vscode" , "com.unity.test-framework" , "com.unity.timeline" , "com.unity.visualscripting" } ;
@@ -187,7 +187,7 @@ static void SetupProject()
187187
188188 UpdatePackages ( ) ;
189189 AssetDatabase . Refresh ( ) ;
190- SaveSettings ( import : true ) ;
190+ SaveSettingsAndImportAssets ( import : true ) ;
191191
192192 // skybox off from lighting settings
193193 RenderSettings . skybox = null ;
@@ -197,7 +197,7 @@ static void SetupProject()
197197 // TODO set background color?
198198
199199 // reset camera pos
200- Camera . main . transform . position = Vector3 . zero ;
200+ Camera . main . transform . position = new Vector3 ( 0 , 3 , - 10 ) ;
201201
202202 // disable editor camera easing and acceleration
203203#if UNITY_2019_1_OR_NEWER
@@ -231,8 +231,9 @@ static void SetupProject()
231231 // self destruct this editor script file
232232 if ( deleteFile == true )
233233 {
234- // FIXME in editor: file is deleted, if re-import some script, while editorwindow is open (resets deletefile var ?)
234+ // FIXME in editor: file is deleted, if re-import some script, while editorwindow is open (resets deletefile bool ?)
235235 var scriptPath = Path . Combine ( assetsFolder , "Editor/InitializeProject.cs" ) ;
236+
236237 Debug . Log ( "Deleting init script: " + scriptPath ) ;
237238 if ( File . Exists ( scriptPath ) ) File . Delete ( scriptPath ) ;
238239 if ( File . Exists ( scriptPath + ".meta" ) ) File . Delete ( scriptPath + ".meta" ) ;
@@ -241,9 +242,8 @@ static void SetupProject()
241242 {
242243 Debug . Log ( "File not deleted when called init manually" ) ;
243244 }
244-
245- // refresh folder
246245 AssetDatabase . Refresh ( ) ;
246+ // if imported assets, need to enter playmode and off for some reason..
247247 }
248248
249249 private void OnEnable ( )
@@ -253,12 +253,54 @@ private void OnEnable()
253253
254254 private void OnDestroy ( )
255255 {
256- SaveSettings ( ) ;
256+ SaveSettingsAndImportAssets ( ) ;
257+ if ( importAssets == true )
258+ {
259+ // have to enter playmode to fully import asset packages???
260+ EditorApplication . EnterPlaymode ( ) ;
261+
262+ var stopperScript = Path . Combine ( assetsFolder , "Editor/StopPlaymode.cs" ) ;
263+ string contents = @"
264+ using UnityEditor;
265+ using UnityEngine;
266+ using System.IO;
267+ using UnityEditor.Callbacks;
268+
269+ [InitializeOnLoad]
270+ public class StopPlaymode
271+ {
272+ static StopPlaymode()
273+ {
274+ EditorApplication.ExitPlaymode();
275+ EditorApplication.delayCall += DeleteSelfScript;
276+ }
277+
278+ static void DeleteSelfScript()
279+ {
280+ var scriptPath = Path.Combine(Application.dataPath, ""Editor/StopPlaymode.cs"");
281+ if (File.Exists(scriptPath))
282+ {
283+ File.Delete(scriptPath);
284+ File.Delete(scriptPath + "".meta"");
285+ AssetDatabase.Refresh();
286+ }
287+ }
288+ }" ;
289+ File . WriteAllText ( stopperScript , contents ) ;
290+ }
291+
292+ //// create dummy editor script to stop playmode and delete itself
293+ //if (File.Exists(stopperScript) == false)
294+ //{
295+ // string contents = "using UnityEditor;\n\n[InitializeOnLoad]\npublic class StopPlaymode\n{\n static StopPlaymode()\n {\n EditorApplication.ExitPlaymode();\n System.IO.File.Delete(\"" + stopperScript + "\");}\n}";
296+ // File.WriteAllText(stopperScript, contents);
297+ //}
298+
257299 }
258300
259301 private void OnDisable ( )
260302 {
261- SaveSettings ( ) ;
303+ SaveSettingsAndImportAssets ( ) ;
262304 }
263305
264306 private static void LoadSettings ( )
@@ -292,7 +334,7 @@ private static void LoadSettings()
292334 }
293335 }
294336
295- static void SaveSettings ( bool import = false )
337+ static void SaveSettingsAndImportAssets ( bool import = false )
296338 {
297339 string listOfAssets = "" ;
298340 string checkedState = "" ;
@@ -420,7 +462,7 @@ static void CreateFolders()
420462 }
421463 }
422464
423- // manifest.json
465+ #region JSON_HANDLING
424466 public class DependenciesManifest
425467 {
426468 public Dictionary < string , string > dependencies { get ; set ; }
@@ -466,4 +508,5 @@ public T Deserialize<T>(string json)
466508 return ( T ) deserializeMethod . Invoke ( null , new object [ ] { json , typeof ( T ) } ) ;
467509 }
468510 }
511+ #endregion
469512}
0 commit comments