forked from Syomus/ProceduralToolkit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ColorHSVDrawer.cs
43 lines (38 loc) · 1.32 KB
/
ColorHSVDrawer.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
using UnityEditor;
using UnityEngine;
namespace ProceduralToolkit.Editor
{
/// <summary>
/// PropertyDrawer for ColorHSV
/// </summary>
[CustomPropertyDrawer(typeof(ColorHSV))]
public class ColorHSVDrawer : PropertyDrawer
{
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
EditorGUI.BeginProperty(position, label, property);
var colorHsv = new ColorHSV();
SerializedProperty valuesIterator = property.Copy();
valuesIterator.NextVisible(true);
for (int i = 0; i < 4; i++)
{
colorHsv[i] = valuesIterator.floatValue;
valuesIterator.NextVisible(false);
}
EditorGUI.BeginChangeCheck();
var color = EditorGUI.ColorField(position, label, colorHsv.ToColor());
if (EditorGUI.EndChangeCheck())
{
colorHsv = new ColorHSV(color);
valuesIterator = property.Copy();
valuesIterator.NextVisible(true);
for (int i = 0; i < 4; i++)
{
valuesIterator.floatValue = colorHsv[i];
valuesIterator.NextVisible(false);
}
}
EditorGUI.EndProperty();
}
}
}