Skip to content

Commit 8cf9f22

Browse files
committed
Minor visual improvements on how ReferencePicker attribute is rendered
1 parent 0d234b2 commit 8cf9f22

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

Assets/Editor Toolbox/Editor/Drawers/Toolbox/PropertySelf/ReferencePickerAttributeDrawer.cs

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -80,12 +80,16 @@ private void UpdateTypeProperty(SerializedProperty property, Type referenceType)
8080
property.serializedObject.ApplyModifiedProperties();
8181
}
8282

83-
private Rect PrepareTypePropertyPosition(in Rect labelPosition, in Rect inputPosition, bool isPropertyExpanded)
83+
private Rect PrepareTypePropertyPosition(bool hasLabel, in Rect labelPosition, in Rect inputPosition, bool isPropertyExpanded)
8484
{
8585
var position = new Rect(inputPosition);
86-
var baseLabelWidth = EditorGUIUtility.labelWidth + labelWidthOffset;
87-
var realLabelWidth = labelPosition.width;
88-
var labelWidth = Mathf.Max(baseLabelWidth, realLabelWidth);
86+
if (!hasLabel)
87+
{
88+
position.xMin += EditorGUIUtility.standardVerticalSpacing;
89+
return position;
90+
}
91+
92+
//skip row only if label exists
8993
if (isPropertyExpanded)
9094
{
9195
//property is expanded and we have place to move it to the next row
@@ -94,8 +98,10 @@ private Rect PrepareTypePropertyPosition(in Rect labelPosition, in Rect inputPos
9498
return position;
9599
}
96100

101+
var baseLabelWidth = EditorGUIUtility.labelWidth + labelWidthOffset;
102+
var realLabelWidth = labelPosition.width;
97103
//adjust position to already rendered label
98-
position.xMin += labelWidth;
104+
position.xMin += Mathf.Max(baseLabelWidth, realLabelWidth);
99105
return position;
100106
}
101107

@@ -111,7 +117,9 @@ protected override void OnGuiSafe(SerializedProperty property, GUIContent label,
111117
EditorGUI.indentLevel++;
112118
var labelRect = propertyScope.LabelRect;
113119
var inputRect = propertyScope.InputRect;
114-
var position = PrepareTypePropertyPosition(in labelRect, in inputRect, isPropertyExpanded);
120+
121+
var hasLabel = !string.IsNullOrEmpty(label.text);
122+
var position = PrepareTypePropertyPosition(hasLabel, in labelRect, in inputRect, isPropertyExpanded);
115123

116124
var parentType = GetParentType(property, attribute);
117125
CreateTypeProperty(position, property, parentType);

0 commit comments

Comments
 (0)