Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HDRP - Use draggable fields for float scalable settings #2227

Merged
merged 2 commits into from
Oct 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions com.unity.render-pipelines.high-definition/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ The version number for this package has increased due to a version update of a r
- Fixed cullmode for SceneSelectionPass.
- Fixed issue that caused non-static object to not render at times in OnEnable reflection probes.
- Baked reflection probes now correctly use static sky for ambient lighting.
- Use draggable fields for float scalable settings

### Changed
- Preparation pass for RTSSShadows to be supported by render graph.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,9 @@ static void MultiField<T>(Rect position, GUIContent[] subLabels, T[] values)
var indentLevel = EditorGUI.indentLevel;
EditorGUI.indentLevel = 0;

// Save labelWidth
float labelWidth = EditorGUIUtility.labelWidth;

// Variable to keep track of the current pixel shift in the rectangle we were assigned for this whole section.
float pixelShift = 0;

Expand All @@ -155,39 +158,27 @@ static void MultiField<T>(Rect position, GUIContent[] subLabels, T[] values)
{
// Let's first compute what is the width of the label of this scalable setting level
// We make sure that the label doesn't go beyond the space available for this scalable setting level
var labelWidth = Mathf.Clamp(CalcPrefixLabelWidth(subLabels[index], (GUIStyle)null), 0, num);

// Draw the Label at the expected position
EditorGUI.LabelField(new Rect(position.x + pixelShift, position.y, labelWidth, position.height), subLabels[index]);

// We need to remove from the position the label size that we've just drawn and shift by it's length
pixelShift += labelWidth;

// The amount of space left for the field
float spaceLeft = num - labelWidth;

// If at least two pixels are left to draw this field, draw it, otherwise, skip
if (spaceLeft > 2)
{
// Define the rectangle for the field
var fieldSlot = new Rect(position.x + pixelShift, position.y, num - labelWidth, position.height);

// Draw the right field depending on its type.
if (typeof(T) == typeof(int))
values[index] = (T)(object)EditorGUI.DelayedIntField(fieldSlot, (int)(object)values[index]);
else if (typeof(T) == typeof(bool))
values[index] = (T)(object)EditorGUI.Toggle(fieldSlot, (bool)(object)values[index]);
else if (typeof(T) == typeof(float))
values[index] = (T)(object)EditorGUI.FloatField(fieldSlot, (float)(object)values[index]);
else if (typeof(T).IsEnum)
values[index] = (T)(object)EditorGUI.EnumPopup(fieldSlot, (Enum)(object)values[index]);
else
throw new ArgumentOutOfRangeException($"<{typeof(T)}> is not a supported type for multi field");
}
EditorGUIUtility.labelWidth = Mathf.Clamp(CalcPrefixLabelWidth(subLabels[index], (GUIStyle)null), 0, num);

// Define the rectangle for the field
var fieldSlot = new Rect(position.x + pixelShift, position.y, num, position.height);

// Draw the right field depending on its type.
if (typeof(T) == typeof(int))
values[index] = (T)(object)EditorGUI.DelayedIntField(fieldSlot, subLabels[index], (int)(object)values[index]);
else if (typeof(T) == typeof(bool))
values[index] = (T)(object)EditorGUI.Toggle(fieldSlot, subLabels[index], (bool)(object)values[index]);
else if (typeof(T) == typeof(float))
values[index] = (T)(object)EditorGUI.FloatField(fieldSlot, subLabels[index], (float)(object)values[index]);
else if (typeof(T).IsEnum)
values[index] = (T)(object)EditorGUI.EnumPopup(fieldSlot, subLabels[index], (Enum)(object)values[index]);
else
throw new ArgumentOutOfRangeException($"<{typeof(T)}> is not a supported type for multi field");

// Shift by the slot that was left for the field
pixelShift += spaceLeft;
// Shift by the slot that was used for the field
pixelShift += num;
}
EditorGUIUtility.labelWidth = labelWidth;
EditorGUI.indentLevel = indentLevel;
}

Expand Down