Skip to content

Commit 04048a4

Browse files
committed
feat: new attribute AutoTypeMenuAttribute, caching, and example
1 parent f938fc5 commit 04048a4

File tree

7 files changed

+188
-58
lines changed

7 files changed

+188
-58
lines changed

Assets/Example/Example.cs

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,85 @@ public Banana ()
5252
}
5353
}
5454

55+
[Serializable]
56+
public class Snack : Food
57+
{
58+
public Snack ()
59+
{
60+
name = "Snack";
61+
kcal = 100f;
62+
}
63+
}
64+
[Serializable]
65+
public class Candy : Snack
66+
{
67+
public Candy ()
68+
{
69+
name = "Candy";
70+
kcal = 100f;
71+
}
72+
}
73+
74+
[Serializable, AutoTypeMenu]
75+
public class Chocolate : Snack
76+
{
77+
public Chocolate ()
78+
{
79+
name = "Chocolate";
80+
kcal = 100f;
81+
}
82+
}
83+
84+
[Serializable]
85+
public class ChocolateBar : Chocolate
86+
{
87+
public ChocolateBar ()
88+
{
89+
name = "ChocolateBar";
90+
kcal = 100f;
91+
}
92+
}
93+
94+
[Serializable]
95+
public class ChocolateIceCream : Chocolate
96+
{
97+
public ChocolateIceCream ()
98+
{
99+
name = "ChocolateIceCream";
100+
kcal = 100f;
101+
}
102+
}
103+
104+
[Serializable]
105+
public class ChocolateBean : Chocolate
106+
{
107+
public ChocolateBean ()
108+
{
109+
name = "ChocolateBean";
110+
kcal = 100f;
111+
}
112+
}
113+
114+
[Serializable]
115+
public class ChocolateBeanAlmond : ChocolateBean
116+
{
117+
public ChocolateBeanAlmond ()
118+
{
119+
name = "ChocolateBeanAlmond";
120+
kcal = 100f;
121+
}
122+
}
123+
124+
[Serializable]
125+
public class ChocolateBeanHazelnut : ChocolateBean
126+
{
127+
public ChocolateBeanHazelnut ()
128+
{
129+
name = "ChocolateBeanHazelnut";
130+
kcal = 100f;
131+
}
132+
}
133+
55134
public class Example : MonoBehaviour
56135
{
57136

Assets/Example/Example.unity

Lines changed: 33 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ OcclusionCullingSettings:
1313
--- !u!104 &2
1414
RenderSettings:
1515
m_ObjectHideFlags: 0
16-
serializedVersion: 10
16+
serializedVersion: 9
1717
m_Fog: 0
1818
m_FogColor: {r: 0.5, g: 0.5, b: 0.5, a: 1}
1919
m_FogMode: 3
@@ -38,12 +38,13 @@ RenderSettings:
3838
m_ReflectionIntensity: 1
3939
m_CustomReflection: {fileID: 0}
4040
m_Sun: {fileID: 0}
41-
m_IndirectSpecularColor: {r: 0, g: 0, b: 0, a: 1}
41+
m_IndirectSpecularColor: {r: 0.44657898, g: 0.4964133, b: 0.5748178, a: 1}
4242
m_UseRadianceAmbientProbe: 0
4343
--- !u!157 &3
4444
LightmapSettings:
4545
m_ObjectHideFlags: 0
4646
serializedVersion: 12
47+
m_GIWorkflowMode: 1
4748
m_GISettings:
4849
serializedVersion: 2
4950
m_BounceScale: 1
@@ -66,6 +67,9 @@ LightmapSettings:
6667
m_LightmapParameters: {fileID: 0}
6768
m_LightmapsBakeMode: 1
6869
m_TextureCompression: 1
70+
m_FinalGather: 0
71+
m_FinalGatherFiltering: 1
72+
m_FinalGatherRayCount: 256
6973
m_ReflectionCompression: 2
7074
m_MixedBakeMode: 2
7175
m_BakeBackend: 1
@@ -100,7 +104,7 @@ NavMeshSettings:
100104
serializedVersion: 2
101105
m_ObjectHideFlags: 0
102106
m_BuildSettings:
103-
serializedVersion: 3
107+
serializedVersion: 2
104108
agentTypeID: 0
105109
agentRadius: 0.5
106110
agentHeight: 2
@@ -113,7 +117,7 @@ NavMeshSettings:
113117
cellSize: 0.16666667
114118
manualTileSize: 0
115119
tileSize: 256
116-
buildHeightMesh: 0
120+
accuratePlacement: 0
117121
maxJobWorkers: 0
118122
preserveTilesOutsideBounds: 0
119123
debug:
@@ -159,17 +163,9 @@ Camera:
159163
m_projectionMatrixMode: 1
160164
m_GateFitMode: 2
161165
m_FOVAxisMode: 0
162-
m_Iso: 200
163-
m_ShutterSpeed: 0.005
164-
m_Aperture: 16
165-
m_FocusDistance: 10
166-
m_FocalLength: 50
167-
m_BladeCount: 5
168-
m_Curvature: {x: 2, y: 11}
169-
m_BarrelClipping: 0.25
170-
m_Anamorphism: 0
171166
m_SensorSize: {x: 36, y: 24}
172167
m_LensShift: {x: 0, y: 0}
168+
m_FocalLength: 50
173169
m_NormalizedViewPortRect:
174170
serializedVersion: 2
175171
x: 0
@@ -203,13 +199,13 @@ Transform:
203199
m_PrefabInstance: {fileID: 0}
204200
m_PrefabAsset: {fileID: 0}
205201
m_GameObject: {fileID: 126803971}
206-
serializedVersion: 2
207202
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
208203
m_LocalPosition: {x: 0, y: 1, z: -10}
209204
m_LocalScale: {x: 1, y: 1, z: 1}
210205
m_ConstrainProportionsScale: 0
211206
m_Children: []
212207
m_Father: {fileID: 0}
208+
m_RootOrder: 3
213209
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
214210
--- !u!1 &586792171
215211
GameObject:
@@ -251,18 +247,34 @@ MonoBehaviour:
251247
foodTwo:
252248
rid: 9020349853700980767
253249
foodThree:
254-
rid: 9020349853700980768
250+
rid: 5331542178295447552
255251
foodsOne:
256252
- rid: 9020349853700980769
257253
- rid: 9020349853700980770
258254
- rid: 9020349853700980771
259255
foodsTwo:
260256
- rid: 9020349853700980772
261-
- rid: 9020349853700980773
257+
- rid: 5331542178476589060
262258
- rid: 9020349853700980774
259+
- rid: 5331542178476589059
263260
references:
264261
version: 2
265262
RefIds:
263+
- rid: 5331542178295447552
264+
type: {class: Grape, ns: , asm: Assembly-CSharp}
265+
data:
266+
name: Grape
267+
kcal: 100
268+
- rid: 5331542178476589059
269+
type: {class: ChocolateBean, ns: , asm: Assembly-CSharp}
270+
data:
271+
name: ChocolateBar
272+
kcal: 100
273+
- rid: 5331542178476589060
274+
type: {class: Grape, ns: , asm: Assembly-CSharp}
275+
data:
276+
name: Peach
277+
kcal: 100
266278
- rid: 9020349853700980763
267279
type: {class: Apple, ns: , asm: Assembly-CSharp}
268280
data:
@@ -288,11 +300,6 @@ MonoBehaviour:
288300
data:
289301
name: Peach
290302
kcal: 100
291-
- rid: 9020349853700980768
292-
type: {class: Grape, ns: , asm: Assembly-CSharp}
293-
data:
294-
name: Grape
295-
kcal: 100
296303
- rid: 9020349853700980769
297304
type: {class: Apple, ns: , asm: Assembly-CSharp}
298305
data:
@@ -313,11 +320,6 @@ MonoBehaviour:
313320
data:
314321
name: Apple
315322
kcal: 100
316-
- rid: 9020349853700980773
317-
type: {class: Peach, ns: , asm: Assembly-CSharp}
318-
data:
319-
name: Peach
320-
kcal: 100
321323
- rid: 9020349853700980774
322324
type: {class: Grape, ns: , asm: Assembly-CSharp}
323325
data:
@@ -330,13 +332,13 @@ Transform:
330332
m_PrefabInstance: {fileID: 0}
331333
m_PrefabAsset: {fileID: 0}
332334
m_GameObject: {fileID: 586792171}
333-
serializedVersion: 2
334335
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
335336
m_LocalPosition: {x: 0, y: 0, z: 0}
336337
m_LocalScale: {x: 1, y: 1, z: 1}
337338
m_ConstrainProportionsScale: 0
338339
m_Children: []
339340
m_Father: {fileID: 0}
341+
m_RootOrder: 1
340342
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
341343
--- !u!1 &994260143
342344
GameObject:
@@ -367,33 +369,20 @@ MonoBehaviour:
367369
m_Script: {fileID: 11500000, guid: dff76005e1dfac84287448b12c4b160e, type: 3}
368370
m_Name:
369371
m_EditorClassIdentifier:
370-
contravarianceActions:
371-
- rid: 3354424774140624943
372-
covarianceActions:
373-
- rid: 3354424774140624944
374-
references:
375-
version: 2
376-
RefIds:
377-
- rid: 3354424774140624943
378-
type: {class: DerivedAction1, ns: , asm: Assembly-CSharp}
379-
data:
380-
- rid: 3354424774140624944
381-
type: {class: NetworkActorAction1, ns: , asm: Assembly-CSharp}
382-
data:
383372
--- !u!4 &994260145
384373
Transform:
385374
m_ObjectHideFlags: 0
386375
m_CorrespondingSourceObject: {fileID: 0}
387376
m_PrefabInstance: {fileID: 0}
388377
m_PrefabAsset: {fileID: 0}
389378
m_GameObject: {fileID: 994260143}
390-
serializedVersion: 2
391379
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
392380
m_LocalPosition: {x: 0, y: 0, z: 0}
393381
m_LocalScale: {x: 1, y: 1, z: 1}
394382
m_ConstrainProportionsScale: 0
395383
m_Children: []
396384
m_Father: {fileID: 0}
385+
m_RootOrder: 2
397386
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
398387
--- !u!1 &1127138992
399388
GameObject:
@@ -420,8 +409,9 @@ Light:
420409
m_PrefabAsset: {fileID: 0}
421410
m_GameObject: {fileID: 1127138992}
422411
m_Enabled: 1
423-
serializedVersion: 11
412+
serializedVersion: 10
424413
m_Type: 1
414+
m_Shape: 0
425415
m_Color: {r: 1, g: 0.95686275, b: 0.8392157, a: 1}
426416
m_Intensity: 1
427417
m_Range: 10
@@ -480,19 +470,11 @@ Transform:
480470
m_PrefabInstance: {fileID: 0}
481471
m_PrefabAsset: {fileID: 0}
482472
m_GameObject: {fileID: 1127138992}
483-
serializedVersion: 2
484473
m_LocalRotation: {x: 0.40821788, y: -0.23456968, z: 0.10938163, w: 0.8754261}
485474
m_LocalPosition: {x: 0, y: 3, z: 0}
486475
m_LocalScale: {x: 1, y: 1, z: 1}
487476
m_ConstrainProportionsScale: 0
488477
m_Children: []
489478
m_Father: {fileID: 0}
479+
m_RootOrder: 0
490480
m_LocalEulerAnglesHint: {x: 50, y: -30, z: 0}
491-
--- !u!1660057539 &9223372036854775807
492-
SceneRoots:
493-
m_ObjectHideFlags: 0
494-
m_Roots:
495-
- {fileID: 126803974}
496-
- {fileID: 1127138994}
497-
- {fileID: 586792173}
498-
- {fileID: 994260145}

Assets/MackySoft/MackySoft.SerializeReferenceExtensions/Editor/AdvancedTypePopup.cs

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public class AdvancedTypePopup : AdvancedDropdown {
2424

2525
const int kMaxNamespaceNestCount = 16;
2626

27-
public static void AddTo (AdvancedDropdownItem root,IEnumerable<Type> types) {
27+
public static void AddTo (AdvancedDropdownItem root,IEnumerable<Type> types, Type baseType) {
2828
int itemCount = 0;
2929

3030
// Add null item.
@@ -39,10 +39,18 @@ public static void AddTo (AdvancedDropdownItem root,IEnumerable<Type> types) {
3939
bool isSingleNamespace = true;
4040
string[] namespaces = new string[kMaxNamespaceNestCount];
4141
foreach (Type type in typeArray) {
42-
string[] splittedTypePath = TypeMenuUtility.GetSplittedTypePath(type);
42+
string[] splittedTypePath = TypeMenuUtility.GetSplittedTypePath(type, baseType);
43+
44+
// If any type has AutoTypeMenuAttribute, it is not single namespace.
45+
if(Attribute.GetCustomAttribute(type, typeof(AutoTypeMenuAttribute)) as AutoTypeMenuAttribute != null) {
46+
isSingleNamespace = false;
47+
break;
48+
}
49+
4350
if (splittedTypePath.Length <= 1) {
4451
continue;
4552
}
53+
4654
// If they explicitly want sub category, let them do.
4755
if (TypeMenuUtility.GetAttribute(type) != null) {
4856
isSingleNamespace = false;
@@ -66,7 +74,7 @@ public static void AddTo (AdvancedDropdownItem root,IEnumerable<Type> types) {
6674

6775
// Add type items.
6876
foreach (Type type in typeArray) {
69-
string[] splittedTypePath = TypeMenuUtility.GetSplittedTypePath(type);
77+
string[] splittedTypePath = TypeMenuUtility.GetSplittedTypePath(type, baseType);
7078
if (splittedTypePath.Length == 0) {
7179
continue;
7280
}
@@ -110,12 +118,14 @@ static AdvancedDropdownItem GetItem (AdvancedDropdownItem parent,string name) {
110118
static readonly float k_HeaderHeight = EditorGUIUtility.singleLineHeight * 2f;
111119

112120
Type[] m_Types;
121+
Type m_BaseType;
113122

114123
public event Action<AdvancedTypePopupItem> OnItemSelected;
115124

116-
public AdvancedTypePopup (IEnumerable<Type> types,int maxLineCount,AdvancedDropdownState state) : base(state) {
125+
public AdvancedTypePopup (IEnumerable<Type> types, Type baseType,int maxLineCount,AdvancedDropdownState state) : base(state) {
117126
SetTypes(types);
118127
minimumSize = new Vector2(minimumSize.x,EditorGUIUtility.singleLineHeight * maxLineCount + k_HeaderHeight);
128+
m_BaseType = baseType;
119129
}
120130

121131
public void SetTypes (IEnumerable<Type> types) {
@@ -124,7 +134,7 @@ public void SetTypes (IEnumerable<Type> types) {
124134

125135
protected override AdvancedDropdownItem BuildRoot () {
126136
var root = new AdvancedDropdownItem("Select Type");
127-
AddTo(root,m_Types);
137+
AddTo(root,m_Types,m_BaseType);
128138
return root;
129139
}
130140

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ TypePopupCache GetTypePopup (SerializedProperty property) {
152152
Type baseType = ManagedReferenceUtility.GetType(managedReferenceFieldTypename);
153153
var popup = new AdvancedTypePopup(
154154
TypeSearch.GetTypes(baseType),
155+
baseType,
155156
k_MaxTypePopupLineCount,
156157
state
157158
);

0 commit comments

Comments
 (0)