Skip to content

Instantly share code, notes, and snippets.

@ncthbrt
Created January 8, 2016 23:06
Show Gist options
  • Save ncthbrt/afcd17edc958e395b144 to your computer and use it in GitHub Desktop.
Save ncthbrt/afcd17edc958e395b144 to your computer and use it in GitHub Desktop.
using UnityEngine;
using UnityEditor;
[CustomPropertyDrawer(typeof(HSVColour))]
public class HSVColourDrawer : PropertyDrawer
{
public override void OnGUI(Rect totalRect, SerializedProperty property, GUIContent label)
{
EditorGUI.BeginProperty(totalRect, label, property);
SerializedProperty hueProperty = property.FindPropertyRelative("_h");
SerializedProperty saturationProperty = property.FindPropertyRelative("_s");
SerializedProperty valueProperty = property.FindPropertyRelative("_v");
SerializedProperty alphaProperty = property.FindPropertyRelative("_a");
HSVColour hsvColour = EditorGUI.ColorField(totalRect, label, new HSVColour(hueProperty.floatValue, saturationProperty.floatValue, valueProperty.floatValue, alphaProperty.floatValue).ToRGB()).ToHSV();
hueProperty.floatValue = hsvColour.H;
saturationProperty.floatValue = hsvColour.S;
valueProperty.floatValue = hsvColour.V;
alphaProperty.floatValue = hsvColour.A;
EditorGUI.EndProperty();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment