Skip to content

Commit 0d5ed35

Browse files
committed
Add vertical spacing, use line height instead of GetPropertyHeight
1 parent 77b328e commit 0d5ed35

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

Editor/EnumBitSetPropertyDrawer.cs

+14-14
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,11 @@ public override void OnGUI(Rect position, SerializedProperty property, GUIConten
1919
string joinedNames = string.Join(" | ", currentEnums);
2020
label.text += " [" + joinedNames + "]";
2121
label.tooltip = joinedNames;
22+
23+
float lineHeight = EditorGUIUtility.singleLineHeight;
24+
float space = EditorGUIUtility.standardVerticalSpacing;
2225

23-
float labelHeight = EditorGUI.GetPropertyHeight(SerializedPropertyType.String, label);
24-
var entryRect = new Rect(position.x, position.y, position.width, labelHeight);
26+
var entryRect = new Rect(position.x, position.y, position.width, lineHeight);
2527
property.isExpanded = EditorGUI.PropertyField(entryRect, property, label);
2628
if (!property.isExpanded)
2729
{
@@ -30,7 +32,7 @@ public override void OnGUI(Rect position, SerializedProperty property, GUIConten
3032

3133
EditorGUI.indentLevel++;
3234
// "Select All" | "Unselect All" buttons
33-
entryRect.y += entryRect.height;
35+
entryRect.y += space + entryRect.height;
3436
var buttonRect = new Rect(entryRect.position, entryRect.size * new Vector2(0.5f, 1f) - BUTTON_PADDING);
3537
bool selectAll = GUI.Button(buttonRect, "Select All");
3638
buttonRect.x += entryRect.width * 0.5f + BUTTON_PADDING.x;
@@ -41,8 +43,7 @@ public override void OnGUI(Rect position, SerializedProperty property, GUIConten
4143
.Where(entry =>
4244
{
4345
var content = new GUIContent(entry.name);
44-
entryRect.y += entryRect.height;
45-
entryRect.height = EditorGUI.GetPropertyHeight(SerializedPropertyType.Boolean, content);
46+
entryRect.y += space + entryRect.height;
4647
bool hasValue = !unselectAll && (selectAll || currentEnums.Contains(entry.name));
4748
return EditorGUI.Toggle(entryRect, content, hasValue);
4849
}
@@ -54,17 +55,16 @@ public override void OnGUI(Rect position, SerializedProperty property, GUIConten
5455

5556
public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
5657
{
57-
float height = EditorGUI.GetPropertyHeight(SerializedPropertyType.String, label);
58-
59-
if (!property.isExpanded)
58+
float lineHeight = EditorGUIUtility.singleLineHeight;
59+
float space = EditorGUIUtility.standardVerticalSpacing;
60+
61+
float height = lineHeight;
62+
if (property.isExpanded)
6063
{
61-
return height;
64+
height += space + lineHeight; // "Select All" | "Unselect All" buttons
65+
height += GetEnumType().GetEnumNames().Length * (space + lineHeight);
6266
}
63-
64-
return height
65-
+ height // "Select All" | "Unselect All" buttons
66-
+ GetEnumType().GetEnumNames()
67-
.Sum(name => EditorGUI.GetPropertyHeight(SerializedPropertyType.Boolean, new GUIContent(name)));
67+
return height;
6868
}
6969

7070
private Type GetEnumType()

0 commit comments

Comments
 (0)