@@ -31,51 +31,74 @@ public TypePopupCache (AdvancedTypePopup typePopup,AdvancedDropdownState state)
31
31
32
32
SerializedProperty m_TargetProperty ;
33
33
34
- public override void OnGUI ( Rect position , SerializedProperty property , GUIContent label ) {
35
- EditorGUI . BeginProperty ( position , label , property ) ;
36
-
37
- if ( property . propertyType == SerializedPropertyType . ManagedReference ) {
34
+ public override void OnGUI ( Rect position , SerializedProperty property , GUIContent label )
35
+ {
36
+ EditorGUI . BeginProperty ( position , label , property ) ;
38
37
39
- // render label first to avoid label overlap for lists
38
+ if ( property . propertyType == SerializedPropertyType . ManagedReference )
39
+ {
40
+ // Render label first to avoid label overlap for lists
40
41
Rect foldoutLabelRect = new Rect ( position ) ;
41
42
foldoutLabelRect . height = EditorGUIUtility . singleLineHeight ;
42
- foldoutLabelRect . x + = EditorGUI . indentLevel * 12 ;
43
+ foldoutLabelRect = EditorGUI . IndentedRect ( foldoutLabelRect ) ;
43
44
Rect popupPosition = EditorGUI . PrefixLabel ( foldoutLabelRect , label ) ;
44
45
45
46
// Draw the subclass selector popup.
46
- if ( EditorGUI . DropdownButton ( popupPosition , GetTypeName ( property ) , FocusType . Keyboard ) ) {
47
+ if ( EditorGUI . DropdownButton ( popupPosition , GetTypeName ( property ) , FocusType . Keyboard ) )
48
+ {
47
49
TypePopupCache popup = GetTypePopup ( property ) ;
48
50
m_TargetProperty = property ;
49
51
popup . TypePopup . Show ( popupPosition ) ;
50
52
}
51
53
52
- // Check if a custom property drawer exists for this type.
53
- PropertyDrawer customDrawer = GetCustomPropertyDrawer ( property ) ;
54
- if ( customDrawer != null )
54
+ // Draw the foldout.
55
+ if ( ! string . IsNullOrEmpty ( property . managedReferenceFullTypename ) )
55
56
{
56
- // Draw the property with custom property drawer.
57
57
Rect foldoutRect = new Rect ( position ) ;
58
58
foldoutRect . height = EditorGUIUtility . singleLineHeight ;
59
+ foldoutRect . x -= 12 ;
59
60
property . isExpanded = EditorGUI . Foldout ( foldoutRect , property . isExpanded , GUIContent . none , true ) ;
61
+ }
60
62
61
- if ( property . isExpanded )
63
+ // Draw property if expanded.
64
+ if ( property . isExpanded )
65
+ {
66
+ using ( new EditorGUI . IndentLevelScope ( ) )
62
67
{
63
- using ( new EditorGUI . IndentLevelScope ( ) )
68
+ // Check if a custom property drawer exists for this type.
69
+ PropertyDrawer customDrawer = GetCustomPropertyDrawer ( property ) ;
70
+ if ( customDrawer != null )
64
71
{
72
+ // Draw the property with custom property drawer.
65
73
Rect indentedRect = position ;
66
74
float foldoutDifference = EditorGUIUtility . singleLineHeight + EditorGUIUtility . standardVerticalSpacing ;
67
75
indentedRect . height = customDrawer . GetPropertyHeight ( property , label ) ;
68
76
indentedRect . y += foldoutDifference ;
69
77
customDrawer . OnGUI ( indentedRect , property , label ) ;
70
78
}
79
+ else
80
+ {
81
+ // Draw the properties of the child elements.
82
+ // NOTE: In the following code, since the foldout layout isn't working properly, I'll iterate through the properties of the child elements myself.
83
+ // EditorGUI.PropertyField(position, property, GUIContent.none, true);
84
+
85
+ Rect childPosition = position ;
86
+ childPosition . y += EditorGUIUtility . singleLineHeight + EditorGUIUtility . standardVerticalSpacing ;
87
+ foreach ( SerializedProperty childProperty in property . GetChildProperties ( ) )
88
+ {
89
+ float height = EditorGUI . GetPropertyHeight ( childProperty , new GUIContent ( childProperty . displayName , childProperty . tooltip ) , true ) ;
90
+ childPosition . height = height ;
91
+ EditorGUI . PropertyField ( childPosition , childProperty , true ) ;
92
+
93
+ childPosition . y += height + EditorGUIUtility . standardVerticalSpacing ;
94
+ }
95
+ }
71
96
}
72
97
}
73
- else
74
- {
75
- EditorGUI . PropertyField ( position , property , GUIContent . none , true ) ;
76
- }
77
- } else {
78
- EditorGUI . LabelField ( position , label , k_IsNotManagedReferenceLabel ) ;
98
+ }
99
+ else
100
+ {
101
+ EditorGUI . LabelField ( position , label , k_IsNotManagedReferenceLabel ) ;
79
102
}
80
103
81
104
EditorGUI . EndProperty ( ) ;
@@ -117,7 +140,6 @@ TypePopupCache GetTypePopup (SerializedProperty property) {
117
140
foreach ( var targetObject in m_TargetProperty . serializedObject . targetObjects ) {
118
141
SerializedObject individualObject = new SerializedObject ( targetObject ) ;
119
142
SerializedProperty individualProperty = individualObject . FindProperty ( m_TargetProperty . propertyPath ) ;
120
-
121
143
object obj = individualProperty . SetManagedReference ( type ) ;
122
144
individualProperty . isExpanded = ( obj != null ) ;
123
145
0 commit comments