Skip to content

Commit 7537a7c

Browse files
committed
Add "Select All" and "Unselect All" buttons to property drawer
1 parent ab975bb commit 7537a7c

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

Editor/EnumBitSetPropertyDrawer.cs

+7-1
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,15 @@ public override void OnGUI(Rect position, SerializedProperty property, GUIConten
3030
var setValuesList = Activator.CreateInstance(enumListType);
3131

3232
EditorGUI.indentLevel++;
33+
entryRect.y += entryRect.height;
34+
var buttonRect = new Rect(entryRect.position, entryRect.size * new Vector2(0.45f, 1f));
35+
bool selectAll = GUI.Button(buttonRect, "Select All");
36+
buttonRect.x = entryRect.width - buttonRect.width;
37+
bool unselectAll = GUI.Button(buttonRect, "Unselect All");
3338
foreach (var (name, value) in GetEnumEntries())
3439
{
3540
var content = new GUIContent(name);
36-
var hasValue = Convert.ToBoolean(Set_Contains.Invoke(currentMask, new[] { value }));
41+
var hasValue = !unselectAll && (selectAll || Convert.ToBoolean(Set_Contains.Invoke(currentMask, new[] { value })));
3742

3843
entryRect.y += entryRect.height;
3944
entryRect.height = EditorGUI.GetPropertyHeight(SerializedPropertyType.Boolean, content);
@@ -57,6 +62,7 @@ public override float GetPropertyHeight(SerializedProperty property, GUIContent
5762

5863
if (_showFold)
5964
{
65+
height += height; // "Select All" | "Unselect All" buttons
6066
foreach (var (name, _) in GetEnumEntries())
6167
{
6268
height += EditorGUI.GetPropertyHeight(SerializedPropertyType.Boolean, new GUIContent(name));

0 commit comments

Comments
 (0)