Merge pull request #72 from mackysoft/feature/hide-in-type-menu

Feature/hide in type menu
This commit is contained in:
Makihiro 2024-10-26 20:13:10 +09:00 committed by GitHub
commit 8f4e361790
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 51 additions and 10 deletions

View File

@ -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

View File

@ -42,6 +42,17 @@ public class Grape : Food
}
}
[Serializable]
[HideInTypeMenu]
public class Banana : Food
{
public Banana ()
{
name = "Banana";
kcal = 100f;
}
}
public class Example : MonoBehaviour
{

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;

View File

@ -0,0 +1,11 @@
#if UNITY_2019_3_OR_NEWER
using System;
/// <summary>
/// An attribute that hides the type in the SubclassSelector.
/// </summary>
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Enum | AttributeTargets.Interface, AllowMultiple = false, Inherited = false)]
public sealed class HideInTypeMenuAttribute : Attribute {
}
#endif

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 9f48f5d86a108b94a9c26381f5ce678c
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: