Skip to content

Commit 6d2e450

Browse files
committed
Merge branch 'master' into bugfix/fix-settings-creation
2 parents e3d73ac + 8e26daf commit 6d2e450

4 files changed

Lines changed: 30 additions & 24 deletions

File tree

CHANGELOG.MD

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
192192
- First initial working version
193193

194194
### [Unreleased]
195-
195+
- Added automatically open of the selected collectable when using the goto button on the CollectableProperty Drawer
196+
- Added type specific GetEnumerator for the Collection
196197

197198

198199
[1.3.2]: https://github.com/badawe/ScriptableObjectCollection/releases/tag/v1.3.2

Scripts/Editor/CollectableScriptableObjectPropertyDrawer.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ public override void OnGUI(Rect position, SerializedProperty property, GUIConten
7676
if (collectableItem != null)
7777
{
7878
DrawEditFoldoutButton(ref popupRect);
79-
DrawGotoButton(collection, ref popupRect);
79+
DrawGotoButton(ref popupRect);
8080
}
8181

8282
using (new EditorGUI.PropertyScope(position, label, property))
@@ -192,7 +192,7 @@ private void DrawSearchablePopup(Rect position, SerializedProperty property)
192192
}
193193
}
194194

195-
public static void DrawGotoButton(ScriptableObjectCollection enumValues, ref Rect popupRect)
195+
public void DrawGotoButton(ref Rect popupRect)
196196
{
197197
Rect buttonRect = popupRect;
198198
buttonRect.width = 30;
@@ -201,7 +201,8 @@ public static void DrawGotoButton(ScriptableObjectCollection enumValues, ref Rec
201201
buttonRect.x += popupRect.width;
202202
if (GUI.Button(buttonRect, CollectionEditorGUI.ARROW_RIGHT_CHAR))
203203
{
204-
Selection.activeObject = enumValues;
204+
Selection.activeObject = collection;
205+
CollectionUtility.SetFoldoutOpen(true, collectableItem, collection);
205206
}
206207
}
207208

Scripts/Editor/Utils/TypeUtility.cs

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,28 +7,16 @@ namespace BrunoMikoski.ScriptableObjectCollections
77
{
88
public static class TypeUtility
99
{
10-
private static List<Type> cachedAvaliableTypes;
10+
private static List<Type> cachedAvailableTypes;
1111

12-
private static List<Type> AvailableTypes
13-
{
14-
get
15-
{
16-
if (cachedAvaliableTypes != null)
17-
return cachedAvaliableTypes;
18-
19-
cachedAvaliableTypes = new List<Type>();
20-
Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
21-
for (int i = 0; i < assemblies.Length; i++)
22-
{
23-
Assembly assembly = assemblies[i];
24-
if (assembly == null)
25-
continue;
26-
27-
cachedAvaliableTypes.AddRange(assembly.GetTypes());
28-
}
12+
private static List<Type> AvailableTypes => cachedAvailableTypes ?? (cachedAvailableTypes = GetTypesFromAssemblies());
2913

30-
return cachedAvaliableTypes;
31-
}
14+
private static List<Type> GetTypesFromAssemblies()
15+
{
16+
return AppDomain.CurrentDomain.GetAssemblies()
17+
.Where(x => x != null)
18+
.SelectMany(x => x.GetTypes())
19+
.ToList();
3220
}
3321

3422
private static Dictionary<Type, List<Type>> typeToSubclasses = new Dictionary<Type, List<Type>>();

Scripts/Runtime/ScriptableObjectCollection.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,22 @@ public static ScriptableObjectCollection<ObjectType> Values
401401
set => base[index] = value;
402402
}
403403

404+
public IEnumerator<ObjectType> GetEnumerator()
405+
{
406+
using (IEnumerator<CollectableScriptableObject> itemEnum = base.GetEnumerator())
407+
{
408+
while (itemEnum.MoveNext())
409+
{
410+
if (itemEnum.Current.IsNull())
411+
continue;
412+
ObjectType obj = itemEnum.Current as ObjectType;
413+
if (obj == null)
414+
continue;
415+
yield return obj;
416+
}
417+
}
418+
}
419+
404420
#if UNITY_EDITOR
405421

406422
public T GetOrAddNew<T>(string targetName = null) where T : ObjectType

0 commit comments

Comments
 (0)