From a8bcece352d968080e4a1aa2f3e9659ffe49a741 Mon Sep 17 00:00:00 2001 From: Johannes Deml Date: Wed, 17 Jan 2024 13:37:32 +0100 Subject: [PATCH 1/2] 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 --- .../Editor/SubclassSelectorDrawer.cs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/Assets/MackySoft/MackySoft.SerializeReferenceExtensions/Editor/SubclassSelectorDrawer.cs b/Assets/MackySoft/MackySoft.SerializeReferenceExtensions/Editor/SubclassSelectorDrawer.cs index aba3b02..2a612ed 100644 --- a/Assets/MackySoft/MackySoft.SerializeReferenceExtensions/Editor/SubclassSelectorDrawer.cs +++ b/Assets/MackySoft/MackySoft.SerializeReferenceExtensions/Editor/SubclassSelectorDrawer.cs @@ -35,6 +35,13 @@ namespace MackySoft.SerializeReferenceExtensions.Editor EditorGUI.BeginProperty(position,label,property); if (property.propertyType == SerializedPropertyType.ManagedReference) { + + // render label first to avoid label overlap for lists + Rect foldoutLabelRect = new Rect(position); + foldoutLabelRect.height = EditorGUIUtility.singleLineHeight; + foldoutLabelRect.x += EditorGUI.indentLevel * 12; + EditorGUI.PrefixLabel(foldoutLabelRect, label); + // Draw the subclass selector popup. Rect popupPosition = new Rect(position); popupPosition.width -= EditorGUIUtility.labelWidth; @@ -54,7 +61,7 @@ namespace MackySoft.SerializeReferenceExtensions.Editor // Draw the property with custom property drawer. Rect foldoutRect = new Rect(position); foldoutRect.height = EditorGUIUtility.singleLineHeight; - property.isExpanded = EditorGUI.Foldout(foldoutRect, property.isExpanded, label, true); + property.isExpanded = EditorGUI.Foldout(foldoutRect, property.isExpanded, GUIContent.none, true); if (property.isExpanded) { @@ -70,7 +77,7 @@ namespace MackySoft.SerializeReferenceExtensions.Editor } else { - EditorGUI.PropertyField(position, property, label, true); + EditorGUI.PropertyField(position, property, GUIContent.none, true); } } else { EditorGUI.LabelField(position,label,k_IsNotManagedReferenceLabel); From c9b5193e51df9ec891c07bb321adfb82bd8d5331 Mon Sep 17 00:00:00 2001 From: Johannes Deml Date: Wed, 7 Feb 2024 19:31:05 +0100 Subject: [PATCH 2/2] Fix use prefixLabel position right away --- .../Editor/SubclassSelectorDrawer.cs | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/Assets/MackySoft/MackySoft.SerializeReferenceExtensions/Editor/SubclassSelectorDrawer.cs b/Assets/MackySoft/MackySoft.SerializeReferenceExtensions/Editor/SubclassSelectorDrawer.cs index 2a612ed..0bfe2be 100644 --- a/Assets/MackySoft/MackySoft.SerializeReferenceExtensions/Editor/SubclassSelectorDrawer.cs +++ b/Assets/MackySoft/MackySoft.SerializeReferenceExtensions/Editor/SubclassSelectorDrawer.cs @@ -35,19 +35,14 @@ namespace MackySoft.SerializeReferenceExtensions.Editor EditorGUI.BeginProperty(position,label,property); if (property.propertyType == SerializedPropertyType.ManagedReference) { - + // render label first to avoid label overlap for lists Rect foldoutLabelRect = new Rect(position); foldoutLabelRect.height = EditorGUIUtility.singleLineHeight; foldoutLabelRect.x += EditorGUI.indentLevel * 12; - EditorGUI.PrefixLabel(foldoutLabelRect, label); - - // Draw the subclass selector popup. - Rect popupPosition = new Rect(position); - popupPosition.width -= EditorGUIUtility.labelWidth; - popupPosition.x += EditorGUIUtility.labelWidth; - popupPosition.height = EditorGUIUtility.singleLineHeight; + Rect popupPosition = EditorGUI.PrefixLabel(foldoutLabelRect, label); + // Draw the subclass selector popup. if (EditorGUI.DropdownButton(popupPosition,GetTypeName(property),FocusType.Keyboard)) { TypePopupCache popup = GetTypePopup(property); m_TargetProperty = property; @@ -62,7 +57,7 @@ namespace MackySoft.SerializeReferenceExtensions.Editor Rect foldoutRect = new Rect(position); foldoutRect.height = EditorGUIUtility.singleLineHeight; property.isExpanded = EditorGUI.Foldout(foldoutRect, property.isExpanded, GUIContent.none, true); - + if (property.isExpanded) { using (new EditorGUI.IndentLevelScope()) @@ -102,7 +97,7 @@ namespace MackySoft.SerializeReferenceExtensions.Editor if (!m_TypePopups.TryGetValue(managedReferenceFieldTypename,out TypePopupCache result)) { var state = new AdvancedDropdownState(); - + Type baseType = ManagedReferenceUtility.GetType(managedReferenceFieldTypename); var popup = new AdvancedTypePopup( TypeCache.GetTypesDerivedFrom(baseType).Append(baseType).Where(p => @@ -125,7 +120,7 @@ namespace MackySoft.SerializeReferenceExtensions.Editor object obj = individualProperty.SetManagedReference(type); individualProperty.isExpanded = (obj != null); - + individualObject.ApplyModifiedProperties(); individualObject.Update(); }