@@ -9,9 +9,11 @@ namespace BrunoMikoski.ScriptableObjectCollections
9
9
{
10
10
public sealed class CreateCollectionWizzard : EditorWindow
11
11
{
12
+ private const string WAITING_SCRIPTS_TO_RECOMPILE_TO_CONTINUE_KEY = "WaitingScriptsToRecompileToContinueKey" ;
12
13
private const string LAST_COLLECTION_SCRIPTABLE_OBJECT_PATH_KEY = "CollectionScriptableObjectPathKey" ;
13
14
private const string LAST_COLLECTION_FULL_NAME_KEY = "CollectionFullNameKey" ;
14
- private const string LAST_COLLECTION_SCRIPT_PATH_KEY = "CollectionScriptPathKey" ;
15
+ private const string LAST_GENERATED_COLLECTION_SCRIPT_PATH_KEY = "CollectionScriptPathKey" ;
16
+ private const string LAST_TARGET_SCRIPTS_FOLDER_KEY = "LastTargetScriptsFolder" ;
15
17
16
18
private DefaultAsset cachedScriptableObjectFolder ;
17
19
private DefaultAsset ScriptableObjectFolder
@@ -26,6 +28,12 @@ private DefaultAsset ScriptableObjectFolder
26
28
cachedScriptableObjectFolder = AssetDatabase . LoadAssetAtPath < DefaultAsset > ( targetFolder ) ;
27
29
return cachedScriptableObjectFolder ;
28
30
}
31
+
32
+ if ( ! string . IsNullOrEmpty ( LastCollectionScriptableObjectPath ) )
33
+ {
34
+ cachedScriptableObjectFolder = AssetDatabase . LoadAssetAtPath < DefaultAsset > ( LastCollectionScriptableObjectPath ) ;
35
+ return cachedScriptableObjectFolder ;
36
+ }
29
37
30
38
if ( ! string . IsNullOrEmpty ( ScriptableObjectCollectionSettings . Instance . DefaultScriptableObjectsFolder ) )
31
39
{
@@ -45,6 +53,12 @@ private DefaultAsset ScriptsFolder
45
53
if ( cachedScriptsFolder != null )
46
54
return cachedScriptsFolder ;
47
55
56
+ if ( ! string . IsNullOrEmpty ( LastScriptsTargetFolder ) )
57
+ {
58
+ cachedScriptsFolder = AssetDatabase . LoadAssetAtPath < DefaultAsset > ( Path . GetDirectoryName ( LastScriptsTargetFolder ) ) ;
59
+ return cachedScriptsFolder ;
60
+ }
61
+
48
62
if ( ! string . IsNullOrEmpty ( targetFolder ) )
49
63
{
50
64
cachedScriptsFolder = AssetDatabase . LoadAssetAtPath < DefaultAsset > ( targetFolder ) ;
@@ -64,11 +78,22 @@ private DefaultAsset ScriptsFolder
64
78
private string cachedNameSpace ;
65
79
private string TargetNameSpace
66
80
{
67
- get => cachedNameSpace ;
81
+ get
82
+ {
83
+ if ( string . IsNullOrEmpty ( cachedNameSpace ) )
84
+ cachedNameSpace = ScriptableObjectCollectionSettings . Instance . DefaultNamespace ;
85
+ return cachedNameSpace ;
86
+ }
68
87
set => cachedNameSpace = value ;
69
88
}
70
89
71
90
91
+ private static bool WaitingRecompileForContinue
92
+ {
93
+ get => EditorPrefs . GetBool ( WAITING_SCRIPTS_TO_RECOMPILE_TO_CONTINUE_KEY , false ) ;
94
+ set => EditorPrefs . SetBool ( WAITING_SCRIPTS_TO_RECOMPILE_TO_CONTINUE_KEY , value ) ;
95
+ }
96
+
72
97
private static string LastCollectionScriptableObjectPath
73
98
{
74
99
get => EditorPrefs . GetString ( LAST_COLLECTION_SCRIPTABLE_OBJECT_PATH_KEY , String . Empty ) ;
@@ -81,10 +106,16 @@ private static string LastCollectionFullName
81
106
set => EditorPrefs . SetString ( LAST_COLLECTION_FULL_NAME_KEY , value ) ;
82
107
}
83
108
84
- private static string LastCollectionScriptPath
109
+ private static string LastScriptsTargetFolder
110
+ {
111
+ get => EditorPrefs . GetString ( LAST_TARGET_SCRIPTS_FOLDER_KEY , String . Empty ) ;
112
+ set => EditorPrefs . SetString ( LAST_TARGET_SCRIPTS_FOLDER_KEY , value ) ;
113
+ }
114
+
115
+ private static string LastGeneratedCollectionScriptPath
85
116
{
86
- get => EditorPrefs . GetString ( LAST_COLLECTION_SCRIPT_PATH_KEY , String . Empty ) ;
87
- set => EditorPrefs . SetString ( LAST_COLLECTION_SCRIPT_PATH_KEY , value ) ;
117
+ get => EditorPrefs . GetString ( LAST_GENERATED_COLLECTION_SCRIPT_PATH_KEY , String . Empty ) ;
118
+ set => EditorPrefs . SetString ( LAST_GENERATED_COLLECTION_SCRIPT_PATH_KEY , value ) ;
88
119
}
89
120
90
121
private bool createFoldForThisCollection = true ;
@@ -175,7 +206,6 @@ private void CreateNewCollection()
175
206
scriptsGenerated |= CreateCollectableScript ( ) ;
176
207
scriptsGenerated |= CreateCollectionScript ( ) ;
177
208
178
- LastCollectionScriptableObjectPath = CreateCollectionObject ( ) ;
179
209
180
210
AssetDatabase . SaveAssets ( ) ;
181
211
AssetDatabase . Refresh ( ) ;
@@ -202,15 +232,16 @@ private string CreateCollectionObject()
202
232
203
233
private bool CreateCollectableScript ( )
204
234
{
205
- string targetFolder = AssetDatabase . GetAssetPath ( ScriptsFolder ) ;
235
+ string folder = AssetDatabase . GetAssetPath ( ScriptsFolder ) ;
236
+ LastScriptsTargetFolder = folder ;
206
237
if ( createFoldForThisCollectionScripts )
207
- targetFolder = Path . Combine ( targetFolder , $ "{ collectionName } ") ;
238
+ folder = Path . Combine ( folder , $ "{ collectionName } ") ;
208
239
209
240
return CodeGenerationUtility . CreateNewEmptyScript ( collectableName ,
210
- targetFolder ,
241
+ folder ,
211
242
TargetNameSpace ,
212
243
string . Empty ,
213
- $ "public class { collectableName } : CollectableScriptableObject",
244
+ $ "public partial class { collectableName } : CollectableScriptableObject",
214
245
typeof ( CollectableScriptableObject ) . Namespace ) ;
215
246
}
216
247
@@ -224,14 +255,14 @@ private bool CreateCollectionScript()
224
255
targetFolder ,
225
256
TargetNameSpace ,
226
257
$ "[CreateAssetMenu(menuName = \" ScriptableObject Collection/Collections/Create { collectionName } \" , fileName = \" { collectionName } \" , order = 0)]",
227
- $ "public partial class { collectionName } : ScriptableObjectCollection<{ collectableName } >", typeof ( ScriptableObjectCollection ) . Namespace , "UnityEngine" ) ;
258
+ $ "public class { collectionName } : ScriptableObjectCollection<{ collectableName } >", typeof ( ScriptableObjectCollection ) . Namespace , "UnityEngine" ) ;
228
259
229
260
if ( string . IsNullOrEmpty ( TargetNameSpace ) )
230
261
LastCollectionFullName = $ "{ collectionName } ";
231
262
else
232
263
LastCollectionFullName = $ "{ TargetNameSpace } .{ collectionName } ";
233
264
234
- LastCollectionScriptPath = Path . Combine ( targetFolder , $ "{ collectionName } .cs") ;
265
+ LastGeneratedCollectionScriptPath = Path . Combine ( targetFolder , $ "{ collectionName } .cs") ;
235
266
return result ;
236
267
}
237
268
@@ -255,13 +286,15 @@ private bool AreSettingsValid()
255
286
[ DidReloadScripts ]
256
287
static void OnAfterScriptsReloading ( )
257
288
{
258
- if ( string . IsNullOrEmpty ( LastCollectionScriptableObjectPath ) )
289
+ if ( ! WaitingRecompileForContinue )
259
290
return ;
260
291
292
+ WaitingRecompileForContinue = false ;
293
+
261
294
ScriptableObjectCollection collectionAsset =
262
295
AssetDatabase . LoadAssetAtPath < ScriptableObjectCollection > ( LastCollectionScriptableObjectPath ) ;
263
296
264
- string assemblyName = CompilationPipeline . GetAssemblyNameFromScriptPath ( LastCollectionScriptPath ) ;
297
+ string assemblyName = CompilationPipeline . GetAssemblyNameFromScriptPath ( LastGeneratedCollectionScriptPath ) ;
265
298
266
299
Type targetType = Type . GetType ( $ "{ LastCollectionFullName } , { assemblyName } ") ;
267
300
@@ -273,9 +306,6 @@ static void OnAfterScriptsReloading()
273
306
collectionScriptableObject . FindProperty ( "m_Script" ) . objectReferenceInstanceIDValue = typeId ;
274
307
collectionScriptableObject . ApplyModifiedProperties ( ) ;
275
308
276
- LastCollectionScriptableObjectPath = string . Empty ;
277
- LastCollectionFullName = string . Empty ;
278
-
279
309
Selection . objects = new [ ] { collectionScriptableObject . targetObject } ;
280
310
EditorGUIUtility . PingObject ( collectionScriptableObject . targetObject ) ;
281
311
GetWindowInstance ( ) . Close ( ) ;
0 commit comments