MinDrawer.cs 1.0 KB

1234567891011121314151617181920212223242526272829
  1. using UnityEngine;
  2. using UnityEngine.PostProcessing;
  3. namespace UnityEditor.PostProcessing
  4. {
  5. [CustomPropertyDrawer(typeof(MinAttribute))]
  6. sealed class MinDrawer : PropertyDrawer
  7. {
  8. public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
  9. {
  10. MinAttribute attribute = (MinAttribute)base.attribute;
  11. if (property.propertyType == SerializedPropertyType.Integer)
  12. {
  13. int v = EditorGUI.IntField(position, label, property.intValue);
  14. property.intValue = (int)Mathf.Max(v, attribute.min);
  15. }
  16. else if (property.propertyType == SerializedPropertyType.Float)
  17. {
  18. float v = EditorGUI.FloatField(position, label, property.floatValue);
  19. property.floatValue = Mathf.Max(v, attribute.min);
  20. }
  21. else
  22. {
  23. EditorGUI.LabelField(position, label.text, "Use Min with float or int.");
  24. }
  25. }
  26. }
  27. }