diff --git a/.github/workflows/package.yaml b/.github/workflows/package.yaml index 5284801..aa8ca4f 100644 --- a/.github/workflows/package.yaml +++ b/.github/workflows/package.yaml @@ -14,7 +14,7 @@ jobs: steps: # Checkout - name: Checkout repository - uses: actions/checkout@v2 + uses: actions/checkout@v4 with: lfs: true @@ -39,7 +39,7 @@ jobs: # Upload - name: Upload .unitypackage - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v4 with: name: Unity Package path: Build \ No newline at end of file diff --git a/Assets/Example/Example.cs b/Assets/Example/Example.cs index 08a4082..310514f 100644 --- a/Assets/Example/Example.cs +++ b/Assets/Example/Example.cs @@ -42,6 +42,17 @@ public class Grape : Food } } +[Serializable] +[HideInTypeMenu] +public class Banana : Food +{ + public Banana () + { + name = "Banana"; + kcal = 100f; + } +} + public class Example : MonoBehaviour { 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; diff --git a/Assets/MackySoft/MackySoft.SerializeReferenceExtensions/Runtime/HideInTypeMenuAttribute.cs b/Assets/MackySoft/MackySoft.SerializeReferenceExtensions/Runtime/HideInTypeMenuAttribute.cs new file mode 100644 index 0000000..716aaac --- /dev/null +++ b/Assets/MackySoft/MackySoft.SerializeReferenceExtensions/Runtime/HideInTypeMenuAttribute.cs @@ -0,0 +1,11 @@ +#if UNITY_2019_3_OR_NEWER +using System; + +/// +/// An attribute that hides the type in the SubclassSelector. +/// +[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Enum | AttributeTargets.Interface, AllowMultiple = false, Inherited = false)] +public sealed class HideInTypeMenuAttribute : Attribute { + +} +#endif \ No newline at end of file diff --git a/Assets/MackySoft/MackySoft.SerializeReferenceExtensions/Runtime/HideInTypeMenuAttribute.cs.meta b/Assets/MackySoft/MackySoft.SerializeReferenceExtensions/Runtime/HideInTypeMenuAttribute.cs.meta new file mode 100644 index 0000000..dd44d0d --- /dev/null +++ b/Assets/MackySoft/MackySoft.SerializeReferenceExtensions/Runtime/HideInTypeMenuAttribute.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 9f48f5d86a108b94a9c26381f5ce678c +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: