forked from Shardstone/trail-into-darkness
30 lines
1.3 KiB
C#
30 lines
1.3 KiB
C#
using UnityEngine;
|
|
using UnityEditor;
|
|
|
|
namespace Jovian.Utilities.Editor {
|
|
public class NumberRangePropertyDrawer : PropertyDrawer {
|
|
private const float PADDING = 1f;
|
|
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) {
|
|
EditorGUI.BeginProperty(position, label, property);
|
|
position = EditorGUI.PrefixLabel(position, GUIUtility.GetControlID(FocusType.Passive), label);
|
|
|
|
float width = position.width * 0.5f - PADDING;
|
|
Rect minRect = new Rect(position.x, position.y, width, position.height);
|
|
Rect maxRect = new Rect(minRect.xMax + PADDING * 2f, position.y, width, position.height);
|
|
|
|
int indentLevel = EditorGUI.indentLevel;
|
|
EditorGUI.indentLevel = 0;
|
|
EditorGUI.PropertyField(minRect, property.FindPropertyRelative("min"), GUIContent.none);
|
|
EditorGUI.PropertyField(maxRect, property.FindPropertyRelative("max"), GUIContent.none);
|
|
EditorGUI.indentLevel = indentLevel;
|
|
EditorGUI.EndProperty();
|
|
}
|
|
}
|
|
|
|
[CustomPropertyDrawer(typeof(FloatRange))]
|
|
public class FloatRangePropertyDrawer : NumberRangePropertyDrawer { }
|
|
|
|
[CustomPropertyDrawer(typeof(IntRange))]
|
|
public class IntRangePropertyDrawer : NumberRangePropertyDrawer { }
|
|
}
|