using System; using UnityEngine; using UnityEngine.Rendering; namespace UnityEditor.Rendering { /// /// This attributes tells an class which type of /// it's an editor for. /// When you make a custom drawer for a parameter, you need add this attribute to the drawer /// class. /// /// [AttributeUsage(AttributeTargets.Class, AllowMultiple = false)] public sealed class VolumeParameterDrawerAttribute : Attribute { /// /// A type derived from . /// public readonly Type parameterType; /// /// Creates a new instance. /// /// A type derived from . public VolumeParameterDrawerAttribute(Type parameterType) { this.parameterType = parameterType; } } /// /// A base class to implement to draw custom editors for custom . /// You must use a to let the editor know which /// parameter this drawer is for. /// /// /// If you do not provide a custom editor for a , Unity uses the buil-in property drawers to draw the /// property as-is. /// /// /// Here's an example about how is implemented: /// /// [VolumeParameterDrawer(typeof(ClampedFloatParameter))] /// class ClampedFloatParameterDrawer : VolumeParameterDrawer /// { /// public override bool OnGUI(SerializedDataParameter parameter, GUIContent title) /// { /// var value = parameter.value; /// /// if (value.propertyType != SerializedPropertyType.Float) /// return false; /// /// var o = parameter.GetObjectRef<ClampedFloatParameter>(); /// EditorGUILayout.Slider(value, o.min, o.max, title); /// value.floatValue = Mathf.Clamp(value.floatValue, o.min, o.max); /// return true; /// } /// } /// /// /// public abstract class VolumeParameterDrawer { // Override this and return false if you want to customize the override checkbox position, // else it'll automatically draw it and put the property content in a horizontal scope. /// /// Override this and return false if you want to customize the position of the override /// checkbox. If you don't, Unity automatically draws the checkbox and puts the property content in a /// horizontal scope. /// /// false if the override checkbox position is customized, true /// otherwise public virtual bool IsAutoProperty() => true; /// /// Draws the parameter in the editor. If the input parameter is invalid you should return /// false so that Unity displays the default editor for this parameter. /// /// The parameter to draw. /// The label and tooltip of the parameter. /// true if the input parameter is valid, false otherwise in which /// case Unity will revert to the default editor for this parameter public abstract bool OnGUI(SerializedDataParameter parameter, GUIContent title); } }