@@ -12,9 +12,6 @@ namespace BrunoMikoski.ScriptableObjectCollections
12
12
[ Serializable ]
13
13
public class SOCSettings
14
14
{
15
- [ SerializeField ]
16
- public List < CollectionSettings > collectionSettings = new ( ) ;
17
-
18
15
private const string STORAGE_PATH = "ProjectSettings/ScriptableObjectCollection.json" ;
19
16
private const int MINIMUM_NAMESPACE_DEPTH = 1 ;
20
17
@@ -162,7 +159,7 @@ public void SetGeneratedScriptsDefaultFilePath(string assetPath)
162
159
163
160
public void Save ( )
164
161
{
165
- string json = EditorJsonUtility . ToJson ( this , prettyPrint : true ) ;
162
+ string json = EditorJsonUtility . ToJson ( this ) ;
166
163
File . WriteAllText ( STORAGE_PATH , json ) ;
167
164
}
168
165
@@ -195,11 +192,8 @@ public void SetGeneratedScriptsParentFolder(ScriptableObjectCollection collectio
195
192
if ( evtNewValue != null )
196
193
assetPath = AssetDatabase . GetAssetPath ( evtNewValue ) ;
197
194
198
-
199
195
CollectionSettings settings = GetOrCreateCollectionSettings ( collection ) ;
200
- settings . ParentFolderPath = assetPath ;
201
-
202
- Save ( ) ;
196
+ settings . SetParentFolderPath ( assetPath ) ;
203
197
}
204
198
205
199
public bool GetUseBaseClassForItem ( ScriptableObjectCollection collection )
@@ -210,10 +204,8 @@ public bool GetUseBaseClassForItem(ScriptableObjectCollection collection)
210
204
public void SetUsingBaseClassForItems ( ScriptableObjectCollection collection , bool useBaseClass )
211
205
{
212
206
CollectionSettings settings = GetOrCreateCollectionSettings ( collection ) ;
213
- settings . UseBaseClassForItems = useBaseClass ;
214
- Save ( ) ;
207
+ settings . SetUseBaseClassForItems ( useBaseClass ) ;
215
208
}
216
-
217
209
218
210
public bool GetWriteAsPartialClass ( ScriptableObjectCollection collection )
219
211
{
@@ -229,11 +221,7 @@ public bool GetWriteAsPartialClass(ScriptableObjectCollection collection)
229
221
public void SetWriteAsPartialClass ( ScriptableObjectCollection collection , bool writeAsPartial )
230
222
{
231
223
CollectionSettings settings = GetOrCreateCollectionSettings ( collection ) ;
232
- if ( settings . WriteAsPartialClass == writeAsPartial )
233
- return ;
234
-
235
- settings . WriteAsPartialClass = writeAsPartial ;
236
- Save ( ) ;
224
+ settings . SetWriteAsPartialClass ( writeAsPartial ) ;
237
225
}
238
226
239
227
public string GetNamespaceForCollection ( ScriptableObjectCollection collection )
@@ -244,8 +232,7 @@ public string GetNamespaceForCollection(ScriptableObjectCollection collection)
244
232
public void SetNamespaceForCollection ( ScriptableObjectCollection collection , string targetNamespace )
245
233
{
246
234
CollectionSettings settings = GetOrCreateCollectionSettings ( collection ) ;
247
- settings . Namespace = targetNamespace ;
248
- Save ( ) ;
235
+ settings . SetNamespace ( targetNamespace ) ;
249
236
}
250
237
251
238
public string GetStaticFilenameForCollection ( ScriptableObjectCollection collection )
@@ -256,8 +243,7 @@ public string GetStaticFilenameForCollection(ScriptableObjectCollection collecti
256
243
public void SetStaticFilenameForCollection ( ScriptableObjectCollection collection , string targetNewName )
257
244
{
258
245
CollectionSettings settings = GetOrCreateCollectionSettings ( collection ) ;
259
- settings . StaticFilename = targetNewName ;
260
- Save ( ) ;
246
+ settings . SetStaticFilename ( targetNewName ) ;
261
247
}
262
248
263
249
public bool GetEnforceIndirectAccess ( ScriptableObjectCollection collection )
@@ -268,52 +254,52 @@ public bool GetEnforceIndirectAccess(ScriptableObjectCollection collection)
268
254
public void SetEnforceIndirectAccess ( ScriptableObjectCollection collection , bool enforceIndirectAccess )
269
255
{
270
256
CollectionSettings settings = GetOrCreateCollectionSettings ( collection ) ;
271
- settings . EnforceIndirectAccess = enforceIndirectAccess ;
272
- Save ( ) ;
257
+ settings . SetEnforceIndirectAccess ( enforceIndirectAccess ) ;
273
258
}
274
259
275
260
public CollectionSettings GetOrCreateCollectionSettings ( ScriptableObjectCollection collection )
276
261
{
277
- CollectionSettings collectionSetting = null ;
278
- for ( int i = 0 ; i < collectionSettings . Count ; i ++ )
262
+ string path = AssetDatabase . GetAssetPath ( collection ) ;
263
+ AssetImporter importer = AssetImporter . GetAtPath ( path ) ;
264
+
265
+ string collectionSettingsData = importer . userData ;
266
+
267
+ CollectionSettings collectionSetting ;
268
+ if ( string . IsNullOrEmpty ( collectionSettingsData ) )
279
269
{
280
- collectionSetting = collectionSettings [ i ] ;
281
- if ( collectionSetting . Guid == collection . GUID )
282
- {
283
- return collectionSetting ;
284
- }
270
+ collectionSetting = new CollectionSettings ( collection ) ;
271
+ }
272
+ else
273
+ {
274
+ collectionSetting = new CollectionSettings ( ) ;
275
+ EditorJsonUtility . FromJsonOverwrite ( importer . userData , collectionSetting ) ;
285
276
}
286
277
287
- collectionSetting = new CollectionSettings ( collection ) ;
288
- collectionSettings . Add ( collectionSetting ) ;
289
- Save ( ) ;
278
+ collectionSetting . SetImporter ( importer ) ;
290
279
return collectionSetting ;
291
280
}
292
281
293
282
public void ResetSettings ( ScriptableObjectCollection collection )
294
283
{
295
- for ( int i = 0 ; i < collectionSettings . Count ; i ++ )
296
- {
297
- CollectionSettings collectionSetting = collectionSettings [ i ] ;
298
- if ( collectionSetting . Guid != collection . GUID )
299
- continue ;
300
-
301
- collectionSettings . RemoveAt ( i ) ;
302
- Save ( ) ;
303
- return ;
304
- }
284
+ CollectionSettings settings = new CollectionSettings ( collection ) ;
285
+ settings . Save ( ) ;
305
286
}
306
287
307
288
public void SetWriteAddressableLoadingMethods ( ScriptableObjectCollection collection , bool evtNewValue )
308
289
{
309
290
CollectionSettings settings = GetOrCreateCollectionSettings ( collection ) ;
310
291
settings . SetWriteAddressableLoadingMethods ( evtNewValue ) ;
311
- Save ( ) ;
312
292
}
313
293
314
294
public bool GetWriteAddressableLoadingMethods ( ScriptableObjectCollection collection )
315
295
{
316
296
return GetOrCreateCollectionSettings ( collection ) . WriteAddressableLoadingMethods ;
317
297
}
298
+
299
+ public void SaveCollectionSettings ( ScriptableObjectCollection collection , bool forceSave = false )
300
+ {
301
+ CollectionSettings settings = GetOrCreateCollectionSettings ( collection ) ;
302
+ settings . Save ( forceSave ) ;
303
+ }
318
304
}
319
305
}
0 commit comments