Skip to content

Commit a8c8b5e

Browse files
committed
add: more tweaks for creating specific libraries
1 parent 2e049e5 commit a8c8b5e

2 files changed

Lines changed: 23 additions & 4 deletions

File tree

Scripts/Editor/ScriptableObjectCollectionUtils.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,21 @@ namespace BrunoMikoski.ScriptableObjectCollections
66
{
77
public static class ScriptableObjectCollectionUtils
88
{
9-
public static T CreateScriptableObjectOfType<T>(DefaultAsset parentFolder, bool createFoldForThisCollection,
9+
public static T CreateScriptableObjectOfType<T>(DefaultAsset parentFolder, bool createFolderForThisCollection,
1010
string targetName) where T : ScriptableObject
1111
{
1212
return CreateScriptableObjectOfType<T>(AssetDatabase.GetAssetPath(parentFolder),
13-
createFoldForThisCollection, targetName);
13+
createFolderForThisCollection, targetName);
1414
}
1515

16-
public static T CreateScriptableObjectOfType<T>(string parentFolderPath, bool createFoldForThisCollection,
16+
public static T CreateScriptableObjectOfType<T>(string parentFolderPath, bool createFolderForThisCollection,
1717
string targetName) where T : ScriptableObject
1818
{
1919
T targetCollection = ScriptableObject.CreateInstance<T>();
2020
targetCollection.name = targetName;
2121

2222
string targetFolderPath = parentFolderPath;
23-
if (createFoldForThisCollection)
23+
if (createFolderForThisCollection)
2424
targetFolderPath = Path.Combine(targetFolderPath, $"{targetName}");
2525

2626
AssetDatabaseUtils.CreatePathIfDontExist(Path.Combine(targetFolderPath, "Items"));

Scripts/Runtime/ScriptableObjectCollection.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,25 @@ public static ScriptableObjectCollection<ObjectType> Values
401401
}
402402

403403
#if UNITY_EDITOR
404+
405+
public ObjectType GetOrAddNew(Type collectionType, string targetName)
406+
{
407+
ObjectType item = Items.FirstOrDefault(o => o.name.Equals(targetName, StringComparison.Ordinal)) as ObjectType;
408+
if (item != null)
409+
return item;
410+
411+
return (ObjectType) AddNew(collectionType, targetName);
412+
}
413+
414+
public ObjectType GetOrAddNew(string targetName)
415+
{
416+
ObjectType item = Items.First(o => o.name.Equals(targetName, StringComparison.Ordinal)) as ObjectType;
417+
if (item != null)
418+
return item;
419+
420+
return AddNew(targetName);
421+
}
422+
404423
public ObjectType AddNew(string targetName)
405424
{
406425
return (ObjectType) AddNew(GetCollectionType(), targetName);

0 commit comments

Comments
 (0)