_xiaofang/xiaofang/Assets/Obi/Scripts/Common/Utils/Attributes/MinMaxAttribute.cs
杨号敬 bcc74f0465 add
2024-12-18 02:18:45 +08:00

42 lines
1009 B
C#

using System;
using UnityEngine;
#if UNITY_EDITOR
using UnityEditor;
#endif
namespace Obi{
[System.AttributeUsage(System.AttributeTargets.Field)]
public class MinMaxAttribute : MultiPropertyAttribute
{
float min;
float max;
public MinMaxAttribute(float min, float max)
{
this.min = min;
this.max = max;
}
#if UNITY_EDITOR
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
if (property.propertyType == SerializedPropertyType.Vector2){
float minValue = property.vector2Value.x;
float maxValue = property.vector2Value.y;
EditorGUI.MinMaxSlider(position, label, ref minValue, ref maxValue, min, max);
var vec = Vector2.zero;
vec.x = minValue;
vec.y = maxValue;
property.vector2Value = vec;
}else{
EditorGUI.LabelField(position, label.text, "Use MinMaxAttribute with Vector2.");
}
}
#endif
}
}