Skip to content

Commit c0bf4a5

Browse files
committed
add: query property drawer
# Conflicts: # Scripts/Editor/PropertyDrawers/CollectionItemQueryPropertyDrawer.cs
1 parent 63cff39 commit c0bf4a5

1 file changed

Lines changed: 4 additions & 17 deletions

File tree

Scripts/Editor/PropertyDrawers/CollectionItemQueryPropertyDrawer.cs

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using System.Collections.Generic;
2-
using BrunoMikoski.ScriptableObjectCollections;
32
using UnityEditor;
43
using UnityEngine;
54

@@ -36,11 +35,9 @@ public override float GetPropertyHeight(SerializedProperty property, GUIContent
3635
height += rowHeight + EditorGUIUtility.standardVerticalSpacing * 2f;
3736
}
3837

39-
// "Add Rule" button
4038
height += EditorGUIUtility.singleLineHeight +
4139
EditorGUIUtility.standardVerticalSpacing;
4240

43-
// Optional help box if there are impossible rules
4441
if (HasImpossibleRules(queryProp))
4542
{
4643
string msg = "This query contains rules that can never be satisfied (conflicting MatchTypes for overlapping items).";
@@ -74,7 +71,6 @@ public override void OnGUI(Rect position, SerializedProperty property, GUIConten
7471

7572
if (property.isExpanded && queryProp != null)
7673
{
77-
// Base rect for all children, one level deeper than the foldout header
7874
int previousIndent = EditorGUI.indentLevel;
7975
EditorGUI.indentLevel = previousIndent + 1;
8076
Rect contentRect = EditorGUI.IndentedRect(new Rect(
@@ -101,23 +97,20 @@ public override void OnGUI(Rect position, SerializedProperty property, GUIConten
10197
Rect rowRect = line;
10298
rowRect.height = rowHeight;
10399

104-
// Remove button on the far right (one line high)
105100
float removeButtonWidth = 20f;
106101
Rect removeRect = new Rect(
107102
rowRect.xMax - removeButtonWidth,
108103
rowRect.y,
109104
removeButtonWidth,
110105
EditorGUIUtility.singleLineHeight);
111106

112-
// MatchType on the left (single-line height)
113107
float matchWidth = 100f;
114108
Rect matchRect = new Rect(
115109
rowRect.x,
116110
rowRect.y,
117111
matchWidth,
118112
EditorGUIUtility.singleLineHeight);
119113

120-
// Picker takes remaining horizontal space
121114
Rect pickerRect = new Rect(
122115
matchRect.xMax + 4f,
123116
rowRect.y,
@@ -141,7 +134,6 @@ public override void OnGUI(Rect position, SerializedProperty property, GUIConten
141134
queryProp.DeleteArrayElementAtIndex(indexToRemove);
142135
}
143136

144-
// Add rule button (fills remaining width under the foldout)
145137
Rect addButtonRect = new Rect(
146138
line.x,
147139
line.y,
@@ -161,7 +153,6 @@ public override void OnGUI(Rect position, SerializedProperty property, GUIConten
161153
line.y += EditorGUIUtility.singleLineHeight +
162154
EditorGUIUtility.standardVerticalSpacing;
163155

164-
// Overall warning if current configuration is impossible
165156
if (HasImpossibleRules(queryProp))
166157
{
167158
Rect helpRect = line;
@@ -175,7 +166,6 @@ public override void OnGUI(Rect position, SerializedProperty property, GUIConten
175166
line.y += helpHeight + EditorGUIUtility.standardVerticalSpacing;
176167
}
177168

178-
// Human-readable summary of what this query does
179169
string summary = BuildSummaryText(queryProp);
180170
if (!string.IsNullOrEmpty(summary))
181171
{
@@ -218,7 +208,6 @@ private void DrawConstrainedMatchType(
218208
}
219209
}
220210

221-
// If no constraints or something went wrong, just draw default popup
222211
if (validValues.Count == 0 || validValues.Count == enumCount)
223212
{
224213
EditorGUI.PropertyField(position, matchTypeProp, GUIContent.none, true);
@@ -227,8 +216,6 @@ private void DrawConstrainedMatchType(
227216

228217
int currentEnumIndex = matchTypeProp.enumValueIndex;
229218

230-
// Ensure current value is always selectable even if now invalid,
231-
// so user can change it back to something valid.
232219
if (!validValues.Contains(currentEnumIndex))
233220
{
234221
validValues.Add(currentEnumIndex);
@@ -468,11 +455,11 @@ private static bool IsCombinationImpossible(int matchA, int matchB)
468455
{
469456
// Based on CollectionItemQuery.MatchType enum:
470457
// 0 = Any, 1 = All, 2 = NotAny, 3 = NotAll
471-
bool aPositive = matchA == 0 || matchA == 1;
472-
bool bPositive = matchB == 0 || matchB == 1;
458+
bool aPositive = matchA is 0 or 1;
459+
bool bPositive = matchB is 0 or 1;
473460

474-
bool aNegative = matchA == 2 || matchA == 3;
475-
bool bNegative = matchB == 2 || matchB == 3;
461+
bool aNegative = matchA is 2 or 3;
462+
bool bNegative = matchB is 2 or 3;
476463

477464
// Treat any combination of positive and negative on overlapping items as impossible.
478465
// Examples:

0 commit comments

Comments
 (0)