From 6269f7f67a18849da31dc41d69910d2d05943da7 Mon Sep 17 00:00:00 2001 From: Makihiro Date: Sat, 26 Oct 2024 20:02:37 +0900 Subject: [PATCH] Add TypeMenuUtility.GetTypes method --- .../Editor/SubclassSelectorDrawer.cs | 10 ++-------- .../Editor/TypeMenuUtility.cs | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/Assets/MackySoft/MackySoft.SerializeReferenceExtensions/Editor/SubclassSelectorDrawer.cs b/Assets/MackySoft/MackySoft.SerializeReferenceExtensions/Editor/SubclassSelectorDrawer.cs index e6a3f3e..6cdbecb 100644 --- a/Assets/MackySoft/MackySoft.SerializeReferenceExtensions/Editor/SubclassSelectorDrawer.cs +++ b/Assets/MackySoft/MackySoft.SerializeReferenceExtensions/Editor/SubclassSelectorDrawer.cs @@ -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 ); diff --git a/Assets/MackySoft/MackySoft.SerializeReferenceExtensions/Editor/TypeMenuUtility.cs b/Assets/MackySoft/MackySoft.SerializeReferenceExtensions/Editor/TypeMenuUtility.cs index 4857c83..3465f19 100644 --- a/Assets/MackySoft/MackySoft.SerializeReferenceExtensions/Editor/TypeMenuUtility.cs +++ b/Assets/MackySoft/MackySoft.SerializeReferenceExtensions/Editor/TypeMenuUtility.cs @@ -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 = ""; + static readonly Type k_UnityObjectType = typeof(UnityEngine.Object); + + public static IEnumerable 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;