1+ using System ;
12using System . Collections ;
23using System . Collections . Generic ;
34using System . IO ;
5+ using System . Linq ;
46using UnityEditor ;
7+ using UnityEditor . PackageManager . UI ;
8+ using UnityEditor . SceneManagement ;
59using UnityEngine ;
610
711namespace UnityLauncherProTools
812{
9- public class InitializeProject
13+ public class InitializeProject : EditorWindow
1014 {
1115 // settings
1216 static string [ ] folders = new string [ ] { "Fonts" , "Materials" , "Models" , "Prefabs" , "Scenes" , "Scripts" , "Shaders" , "Sounds" , "Textures" } ;
1317
18+ static InitializeProject window ;
1419 static string assetsFolder ;
1520 static bool deleteFile = true ;
1621
17- [ MenuItem ( "Tools/Initialize Project" ) ]
22+ // settings
23+ static bool createFolders = true ;
24+
25+ [ MenuItem ( "Tools/UnityLibrary/Initialize Project" ) ]
1826 public static void InitManually ( )
1927 {
2028 // called manually from menu, so dont delete file when testing
@@ -24,32 +32,84 @@ public static void InitManually()
2432
2533 // this method is called from launcher, without parameters, so delete is called
2634 public static void Init ( )
35+ {
36+ window = ( InitializeProject ) EditorWindow . GetWindow ( typeof ( InitializeProject ) ) ;
37+ window . Show ( ) ;
38+ }
39+
40+ void OnGUI ( )
41+ {
42+ GUILayout . Label ( "Project Setup" , EditorStyles . boldLabel ) ;
43+ GUILayout . Space ( 10 ) ;
44+
45+ Checkbox ( "Create Folders" , ref createFolders ) ;
46+
47+ GUILayout . Space ( 10 ) ;
48+ if ( GUILayout . Button ( "Setup Project" , GUILayout . Height ( 64 ) ) ) SetupProject ( ) ;
49+
50+ // enter to confirm
51+ if ( Event . current . keyCode == KeyCode . Return ) SetupProject ( ) ;
52+ }
53+
54+ static void SetupProject ( )
2755 {
2856 assetsFolder = Application . dataPath ;
2957
30- // TODO show window to select options for project init
58+ if ( createFolders ) CreateFolders ( ) ;
59+
60+ // TODO set these somewhere
61+ PlayerSettings . companyName = "Company" ;
62+ PlayerSettings . productName = "Project" ;
3163
32- CreateFolders ( ) ;
33- // TODO adjust project settings, linear, company name
64+ PlayerSettings . colorSpace = ColorSpace . Linear ;
65+
66+ // save scene
67+ var scenePath = "Assets/Scenes/Main.unity" ;
68+ EditorSceneManager . SaveScene ( EditorSceneManager . GetActiveScene ( ) , scenePath ) ;
69+
70+ // add scene to build settings
71+ List < EditorBuildSettingsScene > editorBuildSettingsScenes = new List < EditorBuildSettingsScene > ( ) ;
72+ if ( ! string . IsNullOrEmpty ( scenePath ) ) editorBuildSettingsScenes . Add ( new EditorBuildSettingsScene ( scenePath , true ) ) ;
73+ EditorBuildSettings . scenes = editorBuildSettingsScenes . ToArray ( ) ;
74+
75+ // TODO 2d/3d mode for editor
3476 // TODO remove extra packages
3577 // TODO setup light settings
3678 // TODO adjust mainscene: camera pos, skybox off?
37- // TODO save mainscene
38- // TODO add mainscene to build scenes list
39- // TODO adjust quality settings (but only in mobile?)
79+ Camera . main . transform . position = Vector3 . zero ;
80+
81+ // TODO adjust quality settings (but only in mobile? add toggle: webgl/mobile/windows)
82+
83+ window . Close ( ) ;
4084
4185 // self destruct this editor script file
4286 if ( deleteFile == true )
4387 {
44- var scriptPath = Path . Combine ( assetsFolder , "Scripts/Editor/InitializeProject.cs" ) ;
88+ // FIXME file is deleted, if reimport some script, while editorwindow is open
89+ var scriptPath = Path . Combine ( assetsFolder , "Editor/InitializeProject.cs" ) ;
4590 if ( File . Exists ( scriptPath ) ) File . Delete ( scriptPath ) ;
4691 if ( File . Exists ( scriptPath + ".meta" ) ) File . Delete ( scriptPath + ".meta" ) ;
4792 }
93+ else
94+ {
95+ Debug . Log ( "File not deleted when called init manually" ) ;
96+ }
4897
4998 // refresh folder
5099 AssetDatabase . Refresh ( ) ;
51100 }
52101
102+
103+
104+ // toggle with clickable label text
105+ static void Checkbox ( string label , ref bool value )
106+ {
107+ EditorGUILayout . BeginHorizontal ( ) ;
108+ if ( GUILayout . Button ( label , EditorStyles . label ) ) value = ! value ;
109+ value = EditorGUILayout . Toggle ( "" , value ) ;
110+ EditorGUILayout . EndHorizontal ( ) ;
111+ }
112+
53113 static void CreateFolders ( )
54114 {
55115 // create each folder if it doesnt exists
0 commit comments