Skip to content

Commit eda6aa4

Browse files
authored
Merge pull request #95 from mackysoft/fix/height-calculation
Refactor property height calculation for managed references
2 parents c109b2d + e7fa3b4 commit eda6aa4

File tree

1 file changed

+39
-3
lines changed

1 file changed

+39
-3
lines changed

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

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ public TypePopupCache (AdvancedTypePopup typePopup, AdvancedDropdownState state)
2626

2727
private static readonly GUIContent NullDisplayName = new GUIContent(TypeMenuUtility.NullDisplayName);
2828
private static readonly GUIContent IsNotManagedReferenceLabel = new GUIContent("The property type is not manage reference.");
29+
private static readonly GUIContent TempChildLabel = new GUIContent();
2930

3031
private readonly Dictionary<string, TypePopupCache> typePopups = new Dictionary<string, TypePopupCache>();
3132
private readonly Dictionary<string, GUIContent> typeNameCaches = new Dictionary<string, GUIContent>();
@@ -222,15 +223,50 @@ private GUIContent GetTypeName (SerializedProperty property)
222223

223224
public override float GetPropertyHeight (SerializedProperty property, GUIContent label)
224225
{
226+
if (property.propertyType != SerializedPropertyType.ManagedReference)
227+
{
228+
return EditorGUIUtility.singleLineHeight;
229+
}
230+
if (!property.isExpanded || string.IsNullOrEmpty(property.managedReferenceFullTypename))
231+
{
232+
return EditorGUIUtility.singleLineHeight;
233+
}
234+
235+
float height = EditorGUIUtility.singleLineHeight;
236+
height += EditorGUIUtility.standardVerticalSpacing;
237+
225238
PropertyDrawer customDrawer = GetCustomPropertyDrawer(property);
226239
if (customDrawer != null)
227240
{
228-
return property.isExpanded ? EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing + customDrawer.GetPropertyHeight(property, label) : EditorGUIUtility.singleLineHeight;
241+
height += customDrawer.GetPropertyHeight(property, label);
242+
return height;
229243
}
230-
else
244+
245+
height += GetChildrenHeight(property);
246+
247+
return height;
248+
}
249+
250+
private static float GetChildrenHeight (SerializedProperty property)
251+
{
252+
float height = 0f;
253+
bool first = true;
254+
255+
foreach (SerializedProperty child in property.GetChildProperties())
231256
{
232-
return property.isExpanded ? EditorGUI.GetPropertyHeight(property, true) : EditorGUIUtility.singleLineHeight;
257+
if (!first)
258+
{
259+
height += EditorGUIUtility.standardVerticalSpacing;
260+
}
261+
first = false;
262+
263+
TempChildLabel.text = child.displayName;
264+
TempChildLabel.tooltip = child.tooltip;
265+
266+
height += EditorGUI.GetPropertyHeight(child, TempChildLabel, true);
233267
}
268+
269+
return height;
234270
}
235271

236272
}

0 commit comments

Comments
 (0)