Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/package.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
steps:
# Checkout
- name: Checkout repository
uses: actions/checkout@v2
uses: actions/checkout@v4
with:
lfs: true

Expand All @@ -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
11 changes: 11 additions & 0 deletions Assets/Example/Example.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,17 @@ public Grape ()
}
}

[Serializable]
[HideInTypeMenu]
public class Banana : Food
{
public Banana ()
{
name = "Banana";
kcal = 100f;
}
}

public class Example : MonoBehaviour
{

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public TypePopupCache (AdvancedTypePopup typePopup,AdvancedDropdownState state)
}

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.");

Expand Down Expand Up @@ -129,13 +129,7 @@ TypePopupCache GetTypePopup (SerializedProperty property) {

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
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading