Skip to content

Commit 8f4e361

Browse files
authored
Merge pull request #72 from mackysoft/feature/hide-in-type-menu
Feature/hide in type menu
2 parents b7d76fb + 83b67af commit 8f4e361

File tree

6 files changed

+51
-10
lines changed

6 files changed

+51
-10
lines changed

.github/workflows/package.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
steps:
1515
# Checkout
1616
- name: Checkout repository
17-
uses: actions/checkout@v2
17+
uses: actions/checkout@v4
1818
with:
1919
lfs: true
2020

@@ -39,7 +39,7 @@ jobs:
3939

4040
# Upload
4141
- name: Upload .unitypackage
42-
uses: actions/upload-artifact@v2
42+
uses: actions/upload-artifact@v4
4343
with:
4444
name: Unity Package
4545
path: Build

Assets/Example/Example.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,17 @@ public Grape ()
4242
}
4343
}
4444

45+
[Serializable]
46+
[HideInTypeMenu]
47+
public class Banana : Food
48+
{
49+
public Banana ()
50+
{
51+
name = "Banana";
52+
kcal = 100f;
53+
}
54+
}
55+
4556
public class Example : MonoBehaviour
4657
{
4758

Assets/MackySoft/MackySoft.SerializeReferenceExtensions/Editor/SubclassSelectorDrawer.cs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public TypePopupCache (AdvancedTypePopup typePopup,AdvancedDropdownState state)
2222
}
2323

2424
const int k_MaxTypePopupLineCount = 13;
25-
static readonly Type k_UnityObjectType = typeof(UnityEngine.Object);
25+
2626
static readonly GUIContent k_NullDisplayName = new GUIContent(TypeMenuUtility.k_NullDisplayName);
2727
static readonly GUIContent k_IsNotManagedReferenceLabel = new GUIContent("The property type is not manage reference.");
2828

@@ -129,13 +129,7 @@ TypePopupCache GetTypePopup (SerializedProperty property) {
129129

130130
Type baseType = ManagedReferenceUtility.GetType(managedReferenceFieldTypename);
131131
var popup = new AdvancedTypePopup(
132-
TypeCache.GetTypesDerivedFrom(baseType).Append(baseType).Where(p =>
133-
(p.IsPublic || p.IsNestedPublic || p.IsNestedPrivate) &&
134-
!p.IsAbstract &&
135-
!p.IsGenericType &&
136-
!k_UnityObjectType.IsAssignableFrom(p) &&
137-
Attribute.IsDefined(p,typeof(SerializableAttribute))
138-
),
132+
TypeMenuUtility.GetTypes(baseType),
139133
k_MaxTypePopupLineCount,
140134
state
141135
);

Assets/MackySoft/MackySoft.SerializeReferenceExtensions/Editor/TypeMenuUtility.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,25 @@
22
using System;
33
using System.Linq;
44
using System.Collections.Generic;
5+
using UnityEditor;
56

67
namespace MackySoft.SerializeReferenceExtensions.Editor {
78
public static class TypeMenuUtility {
89

910
public const string k_NullDisplayName = "<null>";
11+
static readonly Type k_UnityObjectType = typeof(UnityEngine.Object);
12+
13+
public static IEnumerable<Type> GetTypes (Type baseType)
14+
{
15+
return TypeCache.GetTypesDerivedFrom(baseType).Append(baseType).Where(p =>
16+
(p.IsPublic || p.IsNestedPublic || p.IsNestedPrivate) &&
17+
!p.IsAbstract &&
18+
!p.IsGenericType &&
19+
!k_UnityObjectType.IsAssignableFrom(p) &&
20+
Attribute.IsDefined(p, typeof(SerializableAttribute)) &&
21+
!Attribute.IsDefined(p, typeof(HideInTypeMenuAttribute))
22+
);
23+
}
1024

1125
public static AddTypeMenuAttribute GetAttribute (Type type) {
1226
return Attribute.GetCustomAttribute(type,typeof(AddTypeMenuAttribute)) as AddTypeMenuAttribute;
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#if UNITY_2019_3_OR_NEWER
2+
using System;
3+
4+
/// <summary>
5+
/// An attribute that hides the type in the SubclassSelector.
6+
/// </summary>
7+
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Enum | AttributeTargets.Interface, AllowMultiple = false, Inherited = false)]
8+
public sealed class HideInTypeMenuAttribute : Attribute {
9+
10+
}
11+
#endif

Assets/MackySoft/MackySoft.SerializeReferenceExtensions/Runtime/HideInTypeMenuAttribute.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)