@@ -31,51 +31,74 @@ public TypePopupCache (AdvancedTypePopup typePopup,AdvancedDropdownState state)
3131
3232 SerializedProperty m_TargetProperty ;
3333
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 ) ;
3837
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
4041 Rect foldoutLabelRect = new Rect ( position ) ;
4142 foldoutLabelRect . height = EditorGUIUtility . singleLineHeight ;
42- foldoutLabelRect . x + = EditorGUI . indentLevel * 12 ;
43+ foldoutLabelRect = EditorGUI . IndentedRect ( foldoutLabelRect ) ;
4344 Rect popupPosition = EditorGUI . PrefixLabel ( foldoutLabelRect , label ) ;
4445
4546 // Draw the subclass selector popup.
46- if ( EditorGUI . DropdownButton ( popupPosition , GetTypeName ( property ) , FocusType . Keyboard ) ) {
47+ if ( EditorGUI . DropdownButton ( popupPosition , GetTypeName ( property ) , FocusType . Keyboard ) )
48+ {
4749 TypePopupCache popup = GetTypePopup ( property ) ;
4850 m_TargetProperty = property ;
4951 popup . TypePopup . Show ( popupPosition ) ;
5052 }
5153
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 ) )
5556 {
56- // Draw the property with custom property drawer.
5757 Rect foldoutRect = new Rect ( position ) ;
5858 foldoutRect . height = EditorGUIUtility . singleLineHeight ;
59+ foldoutRect . x -= 12 ;
5960 property . isExpanded = EditorGUI . Foldout ( foldoutRect , property . isExpanded , GUIContent . none , true ) ;
61+ }
6062
61- if ( property . isExpanded )
63+ // Draw property if expanded.
64+ if ( property . isExpanded )
65+ {
66+ using ( new EditorGUI . IndentLevelScope ( ) )
6267 {
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 )
6471 {
72+ // Draw the property with custom property drawer.
6573 Rect indentedRect = position ;
6674 float foldoutDifference = EditorGUIUtility . singleLineHeight + EditorGUIUtility . standardVerticalSpacing ;
6775 indentedRect . height = customDrawer . GetPropertyHeight ( property , label ) ;
6876 indentedRect . y += foldoutDifference ;
6977 customDrawer . OnGUI ( indentedRect , property , label ) ;
7078 }
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+ }
7196 }
7297 }
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 ) ;
79102 }
80103
81104 EditorGUI . EndProperty ( ) ;
@@ -117,7 +140,6 @@ TypePopupCache GetTypePopup (SerializedProperty property) {
117140 foreach ( var targetObject in m_TargetProperty . serializedObject . targetObjects ) {
118141 SerializedObject individualObject = new SerializedObject ( targetObject ) ;
119142 SerializedProperty individualProperty = individualObject . FindProperty ( m_TargetProperty . propertyPath ) ;
120-
121143 object obj = individualProperty . SetManagedReference ( type ) ;
122144 individualProperty . isExpanded = ( obj != null ) ;
123145
0 commit comments