Exemplo n.º 1
0
        /// <summary>
        /// Returns this colour, but with a specific brightness.
        /// </summary>
        /// <param name="value">The value of the colour (normalized)</param>
        /// <returns>The new colour</returns>
        public static Color WithValue(this Color c, float value)
        {
            HSVColour hsv = new HSVColour(c);

            hsv.V = value;
            return(hsv.ToRGB());
        }
Exemplo n.º 2
0
        /// <summary>
        /// Returns this colour, but with a different hue.
        /// </summary>
        /// <param name="hue">The value of the tone (normalized)</param>
        /// <returns>The new colour</returns>
        public static Color WithHue(this Color c, float hue)
        {
            HSVColour hsv = new HSVColour(c);

            hsv.H = hue;
            return(hsv.ToRGB());
        }
Exemplo n.º 3
0
        /// <summary>
        /// Returns this colour, but with a specific saturation level.
        /// </summary>
        /// <param name="saturation">The saturation of the colour (normalized)</param>
        /// <returns>The new colour</returns>
        public static Color WithSaturation(this Color c, float saturation)
        {
            HSVColour hsv = new HSVColour(c);

            hsv.S = saturation;
            return(hsv.ToRGB());
        }
Exemplo n.º 4
0
        /// <summary>
        /// Returns this colour, but with the brightness shifted by a certain amount.
        /// </summary>
        /// <param name="valueShiftAmount">The amount to value shift (normalized)</param>
        /// <returns>The new value shifted colour</returns>
        public static Color WithValueShift(this Color c, float valueShiftAmount)
        {
            HSVColour hsv = new HSVColour(c);

            hsv.V += valueShiftAmount;
            return(hsv.ToRGB());
        }
Exemplo n.º 5
0
        /// <summary>
        /// Returns this colour, but the saturation shifted by a certain amount.
        /// </summary>
        /// <param name="saturationShiftAmount">The amount to saturation shift (normalized)</param>
        /// <returns>The new saturation shifted colour</returns>
        public static Color WithSaturationShift(this Color c, float saturationShiftAmount)
        {
            HSVColour hsv = new HSVColour(c);

            hsv.S += saturationShiftAmount;
            return(hsv.ToRGB());
        }
Exemplo n.º 6
0
        /// <summary>
        /// Returns this colour, but hue shifted by a certain amount.
        /// </summary>
        /// <param name="hueShiftAmount">The amount to hue shift (normalized)</param>
        /// <returns>The new hue shifted colour</returns>
        public static Color WithHueShift(this Color c, float hueShiftAmount)
        {
            HSVColour hsv = new HSVColour(c);

            hsv.H += hueShiftAmount;
            return(hsv.ToRGB());
        }
Exemplo n.º 7
0
        /// <summary>
        /// Returns this colour, but shifted on any of the hue, saturation or value axes.
        /// </summary>
        /// <param name="hueShiftAmount">The amount to hue shift (normalized)</param>
        /// <param name="saturationShiftAmount">The amount to saturation shift (normalized)</param>
        /// <param name="valueShiftAmount">The amount to value shift (normalized)</param>
        /// <returns>The new shifted colour</returns>
        public static Color WithHSVShift(this Color c, float hueShiftAmount, float saturationShiftAmount, float valueShiftAmount)
        {
            HSVColour hsv = new HSVColour(c);

            hsv.H += hueShiftAmount;
            hsv.S += saturationShiftAmount;
            hsv.V += valueShiftAmount;
            return(hsv.ToRGB());
        }
Exemplo n.º 8
0
        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");

            EditorGUI.BeginChangeCheck();
            HSVColour hsvColour = EditorGUI.ColorField(totalRect, label, new HSVColour(hueProperty.floatValue, saturationProperty.floatValue, valueProperty.floatValue, alphaProperty.floatValue).ToRGB()).ToHSV();

            if (EditorGUI.EndChangeCheck())
            {
                hueProperty.floatValue        = hsvColour.H;
                saturationProperty.floatValue = hsvColour.S;
                valueProperty.floatValue      = hsvColour.V;
                alphaProperty.floatValue      = hsvColour.A;
            }

            EditorGUI.EndProperty();
        }