Merge pull request #72 from mackysoft/feature/hide-in-type-menu
Feature/hide in type menu
This commit is contained in:
commit
8f4e361790
4
.github/workflows/package.yaml
vendored
4
.github/workflows/package.yaml
vendored
@ -14,7 +14,7 @@ jobs:
|
|||||||
steps:
|
steps:
|
||||||
# Checkout
|
# Checkout
|
||||||
- name: Checkout repository
|
- name: Checkout repository
|
||||||
uses: actions/checkout@v2
|
uses: actions/checkout@v4
|
||||||
with:
|
with:
|
||||||
lfs: true
|
lfs: true
|
||||||
|
|
||||||
@ -39,7 +39,7 @@ jobs:
|
|||||||
|
|
||||||
# Upload
|
# Upload
|
||||||
- name: Upload .unitypackage
|
- name: Upload .unitypackage
|
||||||
uses: actions/upload-artifact@v2
|
uses: actions/upload-artifact@v4
|
||||||
with:
|
with:
|
||||||
name: Unity Package
|
name: Unity Package
|
||||||
path: Build
|
path: Build
|
||||||
@ -42,6 +42,17 @@ public class Grape : Food
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Serializable]
|
||||||
|
[HideInTypeMenu]
|
||||||
|
public class Banana : Food
|
||||||
|
{
|
||||||
|
public Banana ()
|
||||||
|
{
|
||||||
|
name = "Banana";
|
||||||
|
kcal = 100f;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public class Example : MonoBehaviour
|
public class Example : MonoBehaviour
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|||||||
@ -22,7 +22,7 @@ namespace MackySoft.SerializeReferenceExtensions.Editor
|
|||||||
}
|
}
|
||||||
|
|
||||||
const int k_MaxTypePopupLineCount = 13;
|
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_NullDisplayName = new GUIContent(TypeMenuUtility.k_NullDisplayName);
|
||||||
static readonly GUIContent k_IsNotManagedReferenceLabel = new GUIContent("The property type is not manage reference.");
|
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);
|
Type baseType = ManagedReferenceUtility.GetType(managedReferenceFieldTypename);
|
||||||
var popup = new AdvancedTypePopup(
|
var popup = new AdvancedTypePopup(
|
||||||
TypeCache.GetTypesDerivedFrom(baseType).Append(baseType).Where(p =>
|
TypeMenuUtility.GetTypes(baseType),
|
||||||
(p.IsPublic || p.IsNestedPublic || p.IsNestedPrivate) &&
|
|
||||||
!p.IsAbstract &&
|
|
||||||
!p.IsGenericType &&
|
|
||||||
!k_UnityObjectType.IsAssignableFrom(p) &&
|
|
||||||
Attribute.IsDefined(p,typeof(SerializableAttribute))
|
|
||||||
),
|
|
||||||
k_MaxTypePopupLineCount,
|
k_MaxTypePopupLineCount,
|
||||||
state
|
state
|
||||||
);
|
);
|
||||||
|
|||||||
@ -2,11 +2,25 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using UnityEditor;
|
||||||
|
|
||||||
namespace MackySoft.SerializeReferenceExtensions.Editor {
|
namespace MackySoft.SerializeReferenceExtensions.Editor {
|
||||||
public static class TypeMenuUtility {
|
public static class TypeMenuUtility {
|
||||||
|
|
||||||
public const string k_NullDisplayName = "<null>";
|
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) {
|
public static AddTypeMenuAttribute GetAttribute (Type type) {
|
||||||
return Attribute.GetCustomAttribute(type,typeof(AddTypeMenuAttribute)) as AddTypeMenuAttribute;
|
return Attribute.GetCustomAttribute(type,typeof(AddTypeMenuAttribute)) as AddTypeMenuAttribute;
|
||||||
|
|||||||
@ -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
|
||||||
@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 9f48f5d86a108b94a9c26381f5ce678c
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
Loading…
x
Reference in New Issue
Block a user