MayHeCome/Assets/Plugins/Febucci/Text Animator/Attributes/Editor/MinValueAttributeDrawer.cs

30 lines
982 B
C#
Raw Normal View History

2024-12-18 09:55:34 +00:00
using UnityEngine;
using UnityEditor;
namespace Febucci.Attributes
{
[CustomPropertyDrawer(typeof(MinValueAttribute))]
public class MinValueAttributeDrawer : PropertyDrawer
{
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
EditorGUI.PropertyField(position, property, label);
switch (property.propertyType)
{
case SerializedPropertyType.Integer:
property.intValue = Mathf.Clamp(property.intValue, (int)(attribute as MinValueAttribute).min, int.MaxValue);
break;
case SerializedPropertyType.Float:
property.floatValue = Mathf.Clamp(property.floatValue, (attribute as MinValueAttribute).min, float.MaxValue);
break;
default:
base.OnGUI(position, property, label);
break;
}
}
}
}