Skip to content

Commit 79fb235

Browse files
Use draggable fields for float scalable settings (#2227)
1 parent ebdc18c commit 79fb235

File tree

2 files changed

+23
-31
lines changed

2 files changed

+23
-31
lines changed

com.unity.render-pipelines.high-definition/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
186186
- Fixed cullmode for SceneSelectionPass.
187187
- Fixed issue that caused non-static object to not render at times in OnEnable reflection probes.
188188
- Baked reflection probes now correctly use static sky for ambient lighting.
189+
- Use draggable fields for float scalable settings
189190

190191
### Changed
191192
- Preparation pass for RTSSShadows to be supported by render graph.

com.unity.render-pipelines.high-definition/Editor/RenderPipeline/Settings/SerializedScalableSetting.cs

Lines changed: 22 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,9 @@ static void MultiField<T>(Rect position, GUIContent[] subLabels, T[] values)
147147
var indentLevel = EditorGUI.indentLevel;
148148
EditorGUI.indentLevel = 0;
149149

150+
// Save labelWidth
151+
float labelWidth = EditorGUIUtility.labelWidth;
152+
150153
// Variable to keep track of the current pixel shift in the rectangle we were assigned for this whole section.
151154
float pixelShift = 0;
152155

@@ -155,39 +158,27 @@ static void MultiField<T>(Rect position, GUIContent[] subLabels, T[] values)
155158
{
156159
// Let's first compute what is the width of the label of this scalable setting level
157160
// We make sure that the label doesn't go beyond the space available for this scalable setting level
158-
var labelWidth = Mathf.Clamp(CalcPrefixLabelWidth(subLabels[index], (GUIStyle)null), 0, num);
159-
160-
// Draw the Label at the expected position
161-
EditorGUI.LabelField(new Rect(position.x + pixelShift, position.y, labelWidth, position.height), subLabels[index]);
162-
163-
// We need to remove from the position the label size that we've just drawn and shift by it's length
164-
pixelShift += labelWidth;
165-
166-
// The amount of space left for the field
167-
float spaceLeft = num - labelWidth;
168-
169-
// If at least two pixels are left to draw this field, draw it, otherwise, skip
170-
if (spaceLeft > 2)
171-
{
172-
// Define the rectangle for the field
173-
var fieldSlot = new Rect(position.x + pixelShift, position.y, num - labelWidth, position.height);
174-
175-
// Draw the right field depending on its type.
176-
if (typeof(T) == typeof(int))
177-
values[index] = (T)(object)EditorGUI.DelayedIntField(fieldSlot, (int)(object)values[index]);
178-
else if (typeof(T) == typeof(bool))
179-
values[index] = (T)(object)EditorGUI.Toggle(fieldSlot, (bool)(object)values[index]);
180-
else if (typeof(T) == typeof(float))
181-
values[index] = (T)(object)EditorGUI.FloatField(fieldSlot, (float)(object)values[index]);
182-
else if (typeof(T).IsEnum)
183-
values[index] = (T)(object)EditorGUI.EnumPopup(fieldSlot, (Enum)(object)values[index]);
184-
else
185-
throw new ArgumentOutOfRangeException($"<{typeof(T)}> is not a supported type for multi field");
186-
}
161+
EditorGUIUtility.labelWidth = Mathf.Clamp(CalcPrefixLabelWidth(subLabels[index], (GUIStyle)null), 0, num);
162+
163+
// Define the rectangle for the field
164+
var fieldSlot = new Rect(position.x + pixelShift, position.y, num, position.height);
165+
166+
// Draw the right field depending on its type.
167+
if (typeof(T) == typeof(int))
168+
values[index] = (T)(object)EditorGUI.DelayedIntField(fieldSlot, subLabels[index], (int)(object)values[index]);
169+
else if (typeof(T) == typeof(bool))
170+
values[index] = (T)(object)EditorGUI.Toggle(fieldSlot, subLabels[index], (bool)(object)values[index]);
171+
else if (typeof(T) == typeof(float))
172+
values[index] = (T)(object)EditorGUI.FloatField(fieldSlot, subLabels[index], (float)(object)values[index]);
173+
else if (typeof(T).IsEnum)
174+
values[index] = (T)(object)EditorGUI.EnumPopup(fieldSlot, subLabels[index], (Enum)(object)values[index]);
175+
else
176+
throw new ArgumentOutOfRangeException($"<{typeof(T)}> is not a supported type for multi field");
187177

188-
// Shift by the slot that was left for the field
189-
pixelShift += spaceLeft;
178+
// Shift by the slot that was used for the field
179+
pixelShift += num;
190180
}
181+
EditorGUIUtility.labelWidth = labelWidth;
191182
EditorGUI.indentLevel = indentLevel;
192183
}
193184

0 commit comments

Comments
 (0)