Files
RebootKit/Editor/PropertyDrawers/ValueRangeDrawer.cs
2025-07-30 05:51:39 +02:00

23 lines
907 B
C#
Executable File

using RebootKit.Engine.Foundation;
using UnityEditor;
using UnityEngine;
namespace RebootKit.Editor.PropertyDrawers {
[CustomPropertyDrawer(typeof(FloatRange))]
public class ValueRangeDrawer : PropertyDrawer {
const string k_minPropertyName = "min";
const string k_maxPropertyName = "max";
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) {
SerializedProperty minProperty = property.FindPropertyRelative(k_minPropertyName);
SerializedProperty maxProperty = property.FindPropertyRelative(k_maxPropertyName);
Vector2 minMax = EditorGUILayout.Vector2Field(label, new Vector2(minProperty.floatValue, maxProperty.floatValue));
if (minMax.x > minMax.y) minMax.y = minMax.x;
minProperty.floatValue = minMax.x;
maxProperty.floatValue = minMax.y;
}
}
}