Add TypeMenuUtility.GetTypes method

This commit is contained in:
Makihiro 2024-10-26 20:02:37 +09:00
parent 63d2d94953
commit 6269f7f67a
2 changed files with 16 additions and 8 deletions

View File

@ -22,7 +22,7 @@ namespace MackySoft.SerializeReferenceExtensions.Editor
}
const int k_MaxTypePopupLineCount = 13;
static readonly Type k_UnityObjectType = typeof(UnityEngine.Object);
static readonly GUIContent k_NullDisplayName = new GUIContent(TypeMenuUtility.k_NullDisplayName);
static readonly GUIContent k_IsNotManagedReferenceLabel = new GUIContent("The property type is not manage reference.");
@ -129,13 +129,7 @@ namespace MackySoft.SerializeReferenceExtensions.Editor
Type baseType = ManagedReferenceUtility.GetType(managedReferenceFieldTypename);
var popup = new AdvancedTypePopup(
TypeCache.GetTypesDerivedFrom(baseType).Append(baseType).Where(p =>
(p.IsPublic || p.IsNestedPublic || p.IsNestedPrivate) &&
!p.IsAbstract &&
!p.IsGenericType &&
!k_UnityObjectType.IsAssignableFrom(p) &&
Attribute.IsDefined(p,typeof(SerializableAttribute))
),
TypeMenuUtility.GetTypes(baseType),
k_MaxTypePopupLineCount,
state
);

View File

@ -2,11 +2,25 @@
using System;
using System.Linq;
using System.Collections.Generic;
using UnityEditor;
namespace MackySoft.SerializeReferenceExtensions.Editor {
public static class TypeMenuUtility {
public const string k_NullDisplayName = "<null>";
static readonly Type k_UnityObjectType = typeof(UnityEngine.Object);
public static IEnumerable<Type> GetTypes (Type baseType)
{
return TypeCache.GetTypesDerivedFrom(baseType).Append(baseType).Where(p =>
(p.IsPublic || p.IsNestedPublic || p.IsNestedPrivate) &&
!p.IsAbstract &&
!p.IsGenericType &&
!k_UnityObjectType.IsAssignableFrom(p) &&
Attribute.IsDefined(p, typeof(SerializableAttribute)) &&
!Attribute.IsDefined(p, typeof(HideInTypeMenuAttribute))
);
}
public static AddTypeMenuAttribute GetAttribute (Type type) {
return Attribute.GetCustomAttribute(type,typeof(AddTypeMenuAttribute)) as AddTypeMenuAttribute;