Created
January 8, 2016 23:06
-
-
Save ncthbrt/afcd17edc958e395b144 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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