Skip to content

Commit 6269f7f

Browse files
committed
Add TypeMenuUtility.GetTypes method
1 parent 63d2d94 commit 6269f7f

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

Assets/MackySoft/MackySoft.SerializeReferenceExtensions/Editor/SubclassSelectorDrawer.cs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public TypePopupCache (AdvancedTypePopup typePopup,AdvancedDropdownState state)
2222
}
2323

2424
const int k_MaxTypePopupLineCount = 13;
25-
static readonly Type k_UnityObjectType = typeof(UnityEngine.Object);
25+
2626
static readonly GUIContent k_NullDisplayName = new GUIContent(TypeMenuUtility.k_NullDisplayName);
2727
static readonly GUIContent k_IsNotManagedReferenceLabel = new GUIContent("The property type is not manage reference.");
2828

@@ -129,13 +129,7 @@ TypePopupCache GetTypePopup (SerializedProperty property) {
129129

130130
Type baseType = ManagedReferenceUtility.GetType(managedReferenceFieldTypename);
131131
var popup = new AdvancedTypePopup(
132-
TypeCache.GetTypesDerivedFrom(baseType).Append(baseType).Where(p =>
133-
(p.IsPublic || p.IsNestedPublic || p.IsNestedPrivate) &&
134-
!p.IsAbstract &&
135-
!p.IsGenericType &&
136-
!k_UnityObjectType.IsAssignableFrom(p) &&
137-
Attribute.IsDefined(p,typeof(SerializableAttribute))
138-
),
132+
TypeMenuUtility.GetTypes(baseType),
139133
k_MaxTypePopupLineCount,
140134
state
141135
);

Assets/MackySoft/MackySoft.SerializeReferenceExtensions/Editor/TypeMenuUtility.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,25 @@
22
using System;
33
using System.Linq;
44
using System.Collections.Generic;
5+
using UnityEditor;
56

67
namespace MackySoft.SerializeReferenceExtensions.Editor {
78
public static class TypeMenuUtility {
89

910
public const string k_NullDisplayName = "<null>";
11+
static readonly Type k_UnityObjectType = typeof(UnityEngine.Object);
12+
13+
public static IEnumerable<Type> GetTypes (Type baseType)
14+
{
15+
return TypeCache.GetTypesDerivedFrom(baseType).Append(baseType).Where(p =>
16+
(p.IsPublic || p.IsNestedPublic || p.IsNestedPrivate) &&
17+
!p.IsAbstract &&
18+
!p.IsGenericType &&
19+
!k_UnityObjectType.IsAssignableFrom(p) &&
20+
Attribute.IsDefined(p, typeof(SerializableAttribute)) &&
21+
!Attribute.IsDefined(p, typeof(HideInTypeMenuAttribute))
22+
);
23+
}
1024

1125
public static AddTypeMenuAttribute GetAttribute (Type type) {
1226
return Attribute.GetCustomAttribute(type,typeof(AddTypeMenuAttribute)) as AddTypeMenuAttribute;

0 commit comments

Comments
 (0)