Game Development Reference
In-Depth Information
07 public class ColorRangeDrawer : PropertyDrawer
08 {
09 //------------------------------------------------------------
10 //Event called by Unity Editor for updating GUI drawing of controls
11 public override void OnGUI (Rect position, SerializedProperty
property, GUIContent label)
12 {
13 //Get color range attribute meta data
14 ColorRangeAttribute range = attribute as ColorRangeAttribute;
15
16 //Add label to inspector
17 position = EditorGUI.PrefixLabel (position, new GUIContent
("Color Lerp"));
18
19 //Define sizes for color rect and slider controls
20 Rect ColorSamplerRect = new Rect(position.x, position.y, 100,
position.height);
21 Rect SliderRect = new Rect(position.x+105, position.y, 200,
position.height);
22
23 //Show color rect control
24 EditorGUI.ColorField(ColorSamplerRect,
property.FindPropertyRelative("BlendedColor").colorValue);
25
26 //Show slider control
27 property.FindPropertyRelative("BlendFactor").floatValue =
EditorGUI.Slider(SliderRect,
property.FindPropertyRelative("BlendFactor").floatValue, 0f, 1f);
28
29 //Update blended color based on slider
30 property.FindPropertyRelative("BlendedColor").colorValue =
Color.Lerp(range.Min, range.Max,
property.FindPropertyRelative("BlendFactor").floatValue);
31 }
32 //------------------------------------------------------------
33 }
34 //------------------------------------------------------------
 
Search WWH ::




Custom Search