Net-Game/Library/PackageCache/com.unity.shadergraph@cdef3258c742/Samples~/UGUIShaders/Scripts/Editor/MinMaxSliderDrawer.cs
2025-03-28 08:33:16 -04:00

32 lines
974 B
C#

using UnityEngine;
using UnityEditor;
namespace Unity.UI.Shaders.Sample.Editor
{
[CustomPropertyDrawer(typeof(MinMaxSliderAttribute))]
public class MinMaxSliderDrawer : PropertyDrawer
{
MinMaxSliderAttribute range => (MinMaxSliderAttribute)attribute;
Vector2 _value;
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
if (property.propertyType == SerializedPropertyType.Vector2)
{
_value = property.vector2Value;
EditorGUI.BeginChangeCheck();
EditorGUI.MinMaxSlider(position, label, ref _value.x, ref _value.y, range.min, range.max);
if (EditorGUI.EndChangeCheck())
{
property.vector2Value = _value;
}
}
else
{
EditorGUI.PropertyField(position, property, label);
}
}
}
}