Game Development Reference
In-Depth Information
As the
ColorBlend
class uses the
[System.Serializable]
attribute, Unity will
automatically render the class and its members inside the Object Inspector when it's
added as a public member of a class. By default, all public members of
ColorBlend
will be rendered, and the
BlendFactor
field will be rendered as an editable field
inside which numbers can be directly entered, including numbers outside
0
and
1
,
as shown here:
Exposing the Color Adjuster class by its defaults and by changing its properties
Let's now start customizing how Unity should render this class inside the Object
Inspector. Begin by creating a new attribute class called
ColorRangeAttribute
,
as shown in the following code sample 8-6:
01 public class ColorRangeAttribute : PropertyAttribute
02 {
03 //------------------------------------------------------------
04 public Color Min;
05 public Color Max;
06 //------------------------------------------------------------
07 public ColorRangeAttribute(float r1, float g1, float b1, float a1,
08 float r2, float g2, float b2, float a2)
09 {
10 this.Min = new Color(r1, g1, b1, a1);
11 this.Max = new Color(r2, g2, b2, a2);
12 }
13 //------------------------------------------------------------
14 }