VolumetricLighting/Assets/MinValueAttribute/Editor/MinValueDrawer.cs
2016-11-01 13:25:56 +01:00

24 lines
681 B
C#

using UnityEngine;
using UnityEditor;
[CustomPropertyDrawer (typeof (MinValueAttribute))]
public class MinValueDrawer : PropertyDrawer {
public override void OnGUI (Rect position, SerializedProperty property, GUIContent label)
{
if (property.propertyType != SerializedPropertyType.Float && property.propertyType != SerializedPropertyType.Integer)
{
EditorGUI.LabelField (position, label.text, "Use MinValue with float or int.");
return;
}
EditorGUI.PropertyField(position, property, label);
if (GUI.changed)
{
MinValueAttribute minValue = attribute as MinValueAttribute;
property.floatValue = Mathf.Max(property.floatValue, minValue.min);
}
}
}