Skip to content

Commit e3b3bfa

Browse files
committed
feat: Added AllowInternal option to TypeOptionsAttribute to include internal types into the dropdown
1 parent 56bbfef commit e3b3bfa

File tree

2 files changed

+28
-3
lines changed

2 files changed

+28
-3
lines changed

Editor/Util/TypeCollector.cs

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System;
44
using System.Collections.Generic;
55
using System.IO;
6+
using System.Linq;
67
using System.Reflection;
78
using TypeReferences;
89
using UnityEngine;
@@ -143,12 +144,18 @@ public static Assembly TryLoadAssembly(string assemblyName)
143144

144145
private static List<Type> GetFilteredTypesFromAssembly(Assembly assembly, TypeOptionsAttribute filter)
145146
{
146-
var visibleTypes = GetVisibleTypesFromAssembly(assembly);
147+
List<Type> assemblyTypes;
148+
149+
assemblyTypes = filter.AllowInternal
150+
? GetAllTypesFromAssembly(assembly)
151+
: GetVisibleTypesFromAssembly(assembly);
152+
147153
var filteredTypes = new List<Type>();
148-
int visibleTypesCount = visibleTypes.Count;
154+
int visibleTypesCount = assemblyTypes.Count;
155+
149156
for (int i = 0; i < visibleTypesCount; i++)
150157
{
151-
Type type = visibleTypes[i];
158+
Type type = assemblyTypes[i];
152159
if (FilterConstraintIsSatisfied(filter, type))
153160
{
154161
filteredTypes.Add(type);
@@ -179,6 +186,19 @@ private static List<Type> GetVisibleTypesFromAssembly(Assembly assembly)
179186
}
180187
}
181188

189+
private static List<Type> GetAllTypesFromAssembly(Assembly assembly)
190+
{
191+
try
192+
{
193+
return assembly.GetTypes().ToList();
194+
}
195+
catch (ReflectionTypeLoadException e)
196+
{
197+
Debug.LogError($"Types could not be extracted from assembly {assembly}: {e.Message}");
198+
return new List<Type>(0);
199+
}
200+
}
201+
182202
private static bool FilterConstraintIsSatisfied(TypeOptionsAttribute filter, Type type)
183203
{
184204
return filter == null || filter.MatchesRequirements(type);

Runtime/Attributes/TypeOptionsAttribute.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,11 @@ public class TypeOptionsAttribute : PropertyAttribute
7373
/// </summary>
7474
[PublicAPI] public bool SerializableOnly;
7575

76+
/// <summary>
77+
/// If enabled, includes internal types in the drop-down. By default, only public ones are shown.
78+
/// </summary>
79+
[PublicAPI] public bool AllowInternal;
80+
7681
/// <summary>
7782
/// Determines whether the specified <see cref="Type"/> matches requirements set in the attribute.
7883
/// </summary>

0 commit comments

Comments
 (0)