A game about forced loneliness, made by TACStudios
1using System;
2using UnityEngine;
3using UnityEngine.Rendering;
4
5namespace UnityEditor.Rendering
6{
7 /// <summary>
8 /// This attributes tells an <see cref="VolumeParameterDrawer"/> class which type of
9 /// <see cref="VolumeParameter"/> it's an editor for.
10 /// When you make a custom drawer for a parameter, you need add this attribute to the drawer
11 /// class.
12 /// </summary>
13 /// <seealso cref="VolumeParameterDrawer"/>
14 [AttributeUsage(AttributeTargets.Class, AllowMultiple = false)]
15 public sealed class VolumeParameterDrawerAttribute : Attribute
16 {
17 /// <summary>
18 /// A type derived from <see cref="VolumeParameter{T}"/>.
19 /// </summary>
20 public readonly Type parameterType;
21
22 /// <summary>
23 /// Creates a new <see cref="VolumeParameterDrawerAttribute"/> instance.
24 /// </summary>
25 /// <param name="parameterType">A type derived from <see cref="VolumeParameter{T}"/>.</param>
26 public VolumeParameterDrawerAttribute(Type parameterType)
27 {
28 this.parameterType = parameterType;
29 }
30 }
31
32 /// <summary>
33 /// A base class to implement to draw custom editors for custom <see cref="VolumeParameter"/>.
34 /// You must use a <see cref="VolumeParameterDrawerAttribute"/> to let the editor know which
35 /// parameter this drawer is for.
36 /// </summary>
37 /// <remarks>
38 /// If you do not provide a custom editor for a <see cref="VolumeParameter"/>, Unity uses the buil-in property drawers to draw the
39 /// property as-is.
40 /// </remarks>
41 /// <example>
42 /// <para>Here's an example about how <see cref="ClampedFloatParameter"/> is implemented:</para>
43 /// <code>
44 /// [VolumeParameterDrawer(typeof(ClampedFloatParameter))]
45 /// class ClampedFloatParameterDrawer : VolumeParameterDrawer
46 /// {
47 /// public override bool OnGUI(SerializedDataParameter parameter, GUIContent title)
48 /// {
49 /// var value = parameter.value;
50 ///
51 /// if (value.propertyType != SerializedPropertyType.Float)
52 /// return false;
53 ///
54 /// var o = parameter.GetObjectRef<ClampedFloatParameter>();
55 /// EditorGUILayout.Slider(value, o.min, o.max, title);
56 /// value.floatValue = Mathf.Clamp(value.floatValue, o.min, o.max);
57 /// return true;
58 /// }
59 /// }
60 /// </code>
61 /// </example>
62 /// <seealso cref="VolumeParameterDrawerAttribute"/>
63 public abstract class VolumeParameterDrawer
64 {
65 // Override this and return false if you want to customize the override checkbox position,
66 // else it'll automatically draw it and put the property content in a horizontal scope.
67
68 /// <summary>
69 /// Override this and return <c>false</c> if you want to customize the position of the override
70 /// checkbox. If you don't, Unity automatically draws the checkbox and puts the property content in a
71 /// horizontal scope.
72 /// </summary>
73 /// <returns><c>false</c> if the override checkbox position is customized, <c>true</c>
74 /// otherwise</returns>
75 public virtual bool IsAutoProperty() => true;
76
77 /// <summary>
78 /// Draws the parameter in the editor. If the input parameter is invalid you should return
79 /// <c>false</c> so that Unity displays the default editor for this parameter.
80 /// </summary>
81 /// <param name="parameter">The parameter to draw.</param>
82 /// <param name="title">The label and tooltip of the parameter.</param>
83 /// <returns><c>true</c> if the input parameter is valid, <c>false</c> otherwise in which
84 /// case Unity will revert to the default editor for this parameter</returns>
85 public abstract bool OnGUI(SerializedDataParameter parameter, GUIContent title);
86 }
87}