Skip to content

Commit 73739e9

Browse files
🔀 Merge develop into main
2 parents e35741b + 83c8cf2 commit 73739e9

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

Assets/Libraries/MinMaxRangeAttribute/Editor/MinMaxRangeDrawer.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ public override void OnGUI(Rect position, SerializedProperty property, GUIConten
4949
var value = property.vector2IntValue;
5050
var minValue = (float)value.x;
5151
var maxValue = (float)value.y;
52+
(minValue, maxValue) = ClampValues(minValue, maxValue, minLimit, maxLimit);
5253
DrawSlider(position, property, minLimit, maxLimit, ref minValue, ref maxValue, BuildIntLabel);
5354
value.x = (int)minValue;
5455
value.y = (int)maxValue;
@@ -59,12 +60,22 @@ public override void OnGUI(Rect position, SerializedProperty property, GUIConten
5960
var value = property.vector2Value;
6061
var minValue = value.x;
6162
var maxValue = value.y;
63+
(minValue, maxValue) = ClampValues(minValue, maxValue, minLimit, maxLimit);
6264
DrawSlider(position, property, minLimit, maxLimit, ref minValue, ref maxValue, BuildFloatLabel);
6365
value.x = minValue;
6466
value.y = maxValue;
6567
property.vector2Value = value;
6668
}
6769

70+
static (float, float) ClampValues(float minValue, float maxValue, float minLimit, float maxLimit)
71+
{
72+
minValue = Math.Max(minLimit, minValue);
73+
minValue = Math.Min(maxLimit, minValue);
74+
maxValue = Math.Min(maxLimit, maxValue);
75+
maxValue = Math.Max(maxValue, minValue);
76+
return (minValue, maxValue);
77+
}
78+
6879
static void DrawSlider(Rect position, SerializedProperty property, float min, float max, ref float x,
6980
ref float y, Func<float, GUIContent> buildLabel)
7081
{

0 commit comments

Comments
 (0)