Skip to content

Commit a8bcece

Browse files
committed
Fix label overlapping button
By drawing the label first we avoid the overlap. By drawing just the label without the foldout we need to work around a unity problem with indentation and apply that ourselves. The foldout property will then be rendered without gui content
1 parent 97c4e63 commit a8bcece

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,13 @@ public override void OnGUI (Rect position,SerializedProperty property,GUIContent
3535
EditorGUI.BeginProperty(position,label,property);
3636

3737
if (property.propertyType == SerializedPropertyType.ManagedReference) {
38+
39+
// render label first to avoid label overlap for lists
40+
Rect foldoutLabelRect = new Rect(position);
41+
foldoutLabelRect.height = EditorGUIUtility.singleLineHeight;
42+
foldoutLabelRect.x += EditorGUI.indentLevel * 12;
43+
EditorGUI.PrefixLabel(foldoutLabelRect, label);
44+
3845
// Draw the subclass selector popup.
3946
Rect popupPosition = new Rect(position);
4047
popupPosition.width -= EditorGUIUtility.labelWidth;
@@ -54,7 +61,7 @@ public override void OnGUI (Rect position,SerializedProperty property,GUIContent
5461
// Draw the property with custom property drawer.
5562
Rect foldoutRect = new Rect(position);
5663
foldoutRect.height = EditorGUIUtility.singleLineHeight;
57-
property.isExpanded = EditorGUI.Foldout(foldoutRect, property.isExpanded, label, true);
64+
property.isExpanded = EditorGUI.Foldout(foldoutRect, property.isExpanded, GUIContent.none, true);
5865

5966
if (property.isExpanded)
6067
{
@@ -70,7 +77,7 @@ public override void OnGUI (Rect position,SerializedProperty property,GUIContent
7077
}
7178
else
7279
{
73-
EditorGUI.PropertyField(position, property, label, true);
80+
EditorGUI.PropertyField(position, property, GUIContent.none, true);
7481
}
7582
} else {
7683
EditorGUI.LabelField(position,label,k_IsNotManagedReferenceLabel);

0 commit comments

Comments
 (0)