Skip to content

Commit 5e82006

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 5e82006

1 file changed

Lines changed: 13 additions & 4 deletions

File tree

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

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

3737
if (property.propertyType == SerializedPropertyType.ManagedReference) {
38+
// Check if a custom property drawer exists for this type.
39+
PropertyDrawer customDrawer = GetCustomPropertyDrawer(property);
40+
if (customDrawer != null)
41+
{
42+
// render label first to avoid label overlap for lists
43+
Rect foldoutLabelRect = new Rect(position);
44+
foldoutLabelRect.height = EditorGUIUtility.singleLineHeight;
45+
foldoutLabelRect.x += EditorGUI.indentLevel * 12;
46+
EditorGUI.PrefixLabel(foldoutLabelRect, label);
47+
}
48+
3849
// Draw the subclass selector popup.
3950
Rect popupPosition = new Rect(position);
4051
popupPosition.width -= EditorGUIUtility.labelWidth;
@@ -46,15 +57,13 @@ public override void OnGUI (Rect position,SerializedProperty property,GUIContent
4657
m_TargetProperty = property;
4758
popup.TypePopup.Show(popupPosition);
4859
}
49-
50-
// Check if a custom property drawer exists for this type.
51-
PropertyDrawer customDrawer = GetCustomPropertyDrawer(property);
60+
5261
if (customDrawer != null)
5362
{
5463
// Draw the property with custom property drawer.
5564
Rect foldoutRect = new Rect(position);
5665
foldoutRect.height = EditorGUIUtility.singleLineHeight;
57-
property.isExpanded = EditorGUI.Foldout(foldoutRect, property.isExpanded, label, true);
66+
property.isExpanded = EditorGUI.Foldout(foldoutRect, property.isExpanded, GUIContent.none, true);
5867

5968
if (property.isExpanded)
6069
{

0 commit comments

Comments
 (0)