4 namespace HKI.Core.Variables.Editor
9 [CustomPropertyDrawer(typeof(MinMaxRangeAttribute))]
13 public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
16 if (property.type !=
"MinMaxRange")
17 Debug.LogWarning(
"Use only with MinMaxRange type");
21 SerializedProperty minValue =
property.FindPropertyRelative(
"RangeStart");
22 SerializedProperty maxValue =
property.FindPropertyRelative(
"RangeEnd");
23 float newMin = minValue.floatValue;
24 float newMax = maxValue.floatValue;
26 float widthLabel = label == null ||
string.IsNullOrEmpty(label.text) ? 0.0f : position.width * 0.425f;
27 float widthLimit = 30.0f;
28 float widthRange = 50.0f;
30 EditorGUI.LabelField(
new Rect(position.x, position.y, widthLabel, position.height), label);
32 EditorGUI.LabelField(
new Rect(position.x + widthLabel, position.y, widthLimit, position.height), range.
MinLimit.ToString(
"0.##"));
34 newMin = Mathf.Clamp(EditorGUI.FloatField(
new Rect(position.x + widthLabel + widthLimit, position.y, widthRange, position.height), newMin), range.
MinLimit, newMax);
36 EditorGUI.MinMaxSlider(
new Rect(position.x + widthLabel + widthLimit + widthRange, position.y, position.width - widthLabel - 2 * (widthLimit + widthRange), position.height), ref newMin, ref newMax, range.
MinLimit, range.
MaxLimit);
38 newMax = Mathf.Clamp(EditorGUI.FloatField(
new Rect(position.x + position.width - widthLimit - widthRange, position.y, widthRange, position.height), newMax), newMin, range.
MaxLimit);
40 EditorGUI.LabelField(
new Rect(position.x + position.width - widthLimit, position.y, widthLimit, position.height), range.
MaxLimit.ToString(
"0.##"));
42 minValue.floatValue = newMin;
43 maxValue.floatValue = newMax;
Custom property drawer for the MinMaxRangeAttribute class.
This Attribute is for having the use of a special property drawer. In this case for the use of a valu...
override void OnGUI(Rect position, SerializedProperty property, GUIContent label)