@@ -12,6 +12,8 @@ namespace UnityLauncherProTools
1212{
1313 public class InitializeProject : EditorWindow
1414 {
15+ static readonly string id = "InitializeProject_" ;
16+
1517 // settings
1618 static string [ ] folders = new string [ ] { "Fonts" , "Materials" , "Models" , "Plugins" , "Prefabs" , "Scenes" , "Scripts" , "Shaders" , "Sounds" , "Textures" } ;
1719
@@ -22,10 +24,13 @@ public class InitializeProject : EditorWindow
2224 static string assetsFolder ;
2325 static bool deleteFile = true ;
2426
25- // settings
2627 static bool createFolders = true ;
2728 static bool updatePackages = true ;
2829
30+ static bool importAssets = true ;
31+ static List < string > items ;
32+ static List < bool > checkedStates ;
33+
2934 [ MenuItem ( "Tools/UnityLibrary/Initialize Project" ) ]
3035 public static void InitManually ( )
3136 {
@@ -38,6 +43,9 @@ public static void InitManually()
3843 public static void Init ( )
3944 {
4045 window = ( InitializeProject ) EditorWindow . GetWindow ( typeof ( InitializeProject ) ) ;
46+ window . titleContent = new GUIContent ( "Initialize Project" ) ;
47+ window . minSize = new Vector2 ( 450 , 550 ) ;
48+ LoadSettings ( ) ;
4149 window . Show ( ) ;
4250 }
4351
@@ -47,15 +55,109 @@ void OnGUI()
4755 GUILayout . Space ( 10 ) ;
4856
4957 Checkbox ( "Create Folders" , ref createFolders ) ;
50- Checkbox ( "updatePackages" , ref updatePackages ) ;
58+ Checkbox ( "Update Packages" , ref updatePackages ) ;
59+ Checkbox ( "Import Assets" , ref importAssets ) ;
5160
5261 GUILayout . Space ( 10 ) ;
53- if ( GUILayout . Button ( "Setup Project" , GUILayout . Height ( 64 ) ) ) SetupProject ( ) ;
62+ if ( GUILayout . Button ( "Setup Project" , GUILayout . Height ( 64 ) ) )
63+ {
64+ SetupProject ( ) ;
65+ }
66+
67+ DrawAddAssets ( ) ;
68+ DrawAssetList ( ) ;
5469
5570 // enter to confirm
5671 if ( Event . current . keyCode == KeyCode . Return ) SetupProject ( ) ;
5772 }
5873
74+ static void DrawAssetList ( )
75+ {
76+ GUILayout . Space ( 5 ) ;
77+ GUILayout . Box ( "" , GUILayout . ExpandWidth ( true ) , GUILayout . Height ( 2 ) ) ;
78+ GUILayout . Space ( 5 ) ;
79+
80+ // Draw list of items
81+ for ( int i = 0 ; i < items . Count ; i ++ )
82+ {
83+ GUILayout . BeginHorizontal ( ) ;
84+
85+ bool newState = EditorGUILayout . Toggle ( checkedStates [ i ] , GUILayout . Width ( 20 ) ) ;
86+ if ( newState != checkedStates [ i ] )
87+ {
88+ checkedStates [ i ] = newState ;
89+ }
90+
91+ var filename = Path . GetFileName ( items [ i ] ) ;
92+ GUILayout . Label ( filename , GUILayout . Width ( 350 ) ) ;
93+
94+ EditorGUI . BeginDisabledGroup ( i == 0 ) ;
95+ if ( GUILayout . Button ( "^" , GUILayout . Width ( 20 ) ) )
96+ {
97+ var item = items [ i ] ;
98+ var state = checkedStates [ i ] ;
99+ items . RemoveAt ( i ) ;
100+ checkedStates . RemoveAt ( i ) ;
101+ items . Insert ( i - 1 , item ) ;
102+ checkedStates . Insert ( i - 1 , state ) ;
103+ }
104+ EditorGUI . EndDisabledGroup ( ) ;
105+
106+ EditorGUI . BeginDisabledGroup ( i == items . Count - 1 ) ;
107+ if ( GUILayout . Button ( "v" , GUILayout . Width ( 20 ) ) )
108+ {
109+ var item = items [ i ] ;
110+ var state = checkedStates [ i ] ;
111+ items . RemoveAt ( i ) ;
112+ checkedStates . RemoveAt ( i ) ;
113+ items . Insert ( i + 1 , item ) ;
114+ checkedStates . Insert ( i + 1 , state ) ;
115+ }
116+ EditorGUI . EndDisabledGroup ( ) ;
117+
118+ if ( GUILayout . Button ( "x" , GUILayout . Width ( 20 ) ) )
119+ {
120+ items . RemoveAt ( i ) ;
121+ checkedStates . RemoveAt ( i ) ;
122+ }
123+ GUILayout . EndHorizontal ( ) ;
124+ }
125+ }
126+
127+ private static void DrawAddAssets ( )
128+ {
129+ GUILayout . Space ( 10 ) ;
130+ GUILayout . Box ( "" , GUILayout . ExpandWidth ( true ) , GUILayout . Height ( 2 ) ) ;
131+
132+ if ( GUILayout . Button ( "Select assets..." ) )
133+ {
134+ // TODO add support for custom asset store folder (2022 and later)
135+ var assetsFolder = Path . Combine ( Environment . GetFolderPath ( Environment . SpecialFolder . ApplicationData ) , "Unity\\ Asset Store-5.x" ) ;
136+ if ( Directory . Exists ( assetsFolder ) == true )
137+ {
138+ string path = EditorUtility . OpenFilePanel ( "Select Asset to Include" , assetsFolder , "unitypackage" ) ;
139+ if ( ! string . IsNullOrEmpty ( path ) )
140+ {
141+ // dont add if already in list
142+ if ( items . Contains ( path ) == false )
143+ {
144+ items . Add ( path ) ;
145+ checkedStates . Add ( true ) ;
146+ }
147+ else
148+ {
149+ var filename = Path . GetFileName ( path ) ;
150+ Debug . LogWarning ( filename + " is already added." ) ;
151+ }
152+ }
153+ }
154+ else
155+ {
156+ Debug . LogError ( "Asset folder not found: " + assetsFolder ) ;
157+ }
158+ }
159+ }
160+
59161 static void SetupProject ( )
60162 {
61163 assetsFolder = Application . dataPath ;
@@ -85,6 +187,8 @@ static void SetupProject()
85187
86188 UpdatePackages ( ) ;
87189
190+ SaveSettings ( import : true ) ;
191+
88192 // skybox off from lighting settings
89193 RenderSettings . skybox = null ;
90194
@@ -142,6 +246,78 @@ static void SetupProject()
142246 AssetDatabase . Refresh ( ) ;
143247 }
144248
249+ private void OnEnable ( )
250+ {
251+ LoadSettings ( ) ;
252+ }
253+
254+ private void OnDestroy ( )
255+ {
256+ SaveSettings ( ) ;
257+ }
258+
259+ private void OnDisable ( )
260+ {
261+ SaveSettings ( ) ;
262+ }
263+
264+ private static void LoadSettings ( )
265+ {
266+ items = new List < string > ( ) ;
267+ checkedStates = new List < bool > ( ) ;
268+
269+ importAssets = EditorPrefs . GetBool ( id + "importAssets" , true ) ;
270+ var listOfAssets = EditorPrefs . GetString ( id + "listOfAssets" , "" ) ;
271+ var checkedState = EditorPrefs . GetString ( id + "checkedState" , "" ) ;
272+
273+ if ( listOfAssets != "" )
274+ {
275+ var assets = listOfAssets . Split ( '|' ) ;
276+ foreach ( var asset in assets )
277+ {
278+ if ( asset != "" )
279+ {
280+ items . Add ( asset ) ;
281+ }
282+ }
283+
284+ var states = checkedState . Split ( '|' ) ;
285+ foreach ( var state in states )
286+ {
287+ if ( state != "" )
288+ {
289+ checkedStates . Add ( state == "1" ) ;
290+ }
291+ }
292+ }
293+ }
294+
295+ static void SaveSettings ( bool import = false )
296+ {
297+ string listOfAssets = "" ;
298+ string checkedState = "" ;
299+ for ( int i = 0 ; i < items . Count ; i ++ )
300+ {
301+ if ( checkedStates [ i ] == true )
302+ {
303+ if ( import == true )
304+ {
305+ if ( File . Exists ( items [ i ] ) == false )
306+ {
307+ Debug . LogError ( "File not found: " + items [ i ] ) ;
308+ continue ;
309+ }
310+ Debug . Log ( "Importing: " + items [ i ] ) ;
311+ AssetDatabase . ImportPackage ( items [ i ] , false ) ;
312+ }
313+ }
314+ listOfAssets += items [ i ] + "|" ;
315+ checkedState += ( checkedStates [ i ] == true ? 1 : 0 ) + "|" ;
316+ }
317+ EditorPrefs . SetString ( id + "listOfAssets" , listOfAssets ) ;
318+ EditorPrefs . SetString ( id + "checkedState" , checkedState ) ;
319+ EditorPrefs . SetBool ( id + "importAssets" , importAssets ) ;
320+ }
145321
146322 static void UpdatePackages ( )
147323 {
@@ -222,8 +398,8 @@ static void UpdatePackages()
222398 static void Checkbox ( string label , ref bool value )
223399 {
224400 EditorGUILayout . BeginHorizontal ( ) ;
225- if ( GUILayout . Button ( label , EditorStyles . label ) ) value = ! value ;
226- value = EditorGUILayout . Toggle ( "" , value ) ;
401+ // if (GUILayout.Button(label, EditorStyles.label)) value = !value;
402+ value = EditorGUILayout . ToggleLeft ( label , value ) ;
227403 EditorGUILayout . EndHorizontal ( ) ;
228404 }
229405
0 commit comments