Пример #1
0
        /// <summary>
        /// Generates a RGB hsvColor using random hue and specified saturation and value (brightness)
        /// </summary>
        /// <param name="saturation">Saturation of the hsvColor</param>
        /// <param name="value">Brightness of the hsvColor</param>
        /// <param name="useGoldenRatio">'True': the golden ration will be used to better randomize the hue</param>
        /// <returns>RGB hsvColor</returns>
        public static Color WithSaturationValue(float saturation, float value, bool useGoldenRatio = false)
        {
            //Rangos: 0 - 0.16667 - 0.33337 - 0.5 - 0.66667 - 0.83337 - 1
            float newHue = UnityEngine.Random.value;

            if (useGoldenRatio)
            {
                float goldenRadioConj = 0.618033988749895f;
                newHue += goldenRadioConj;
                newHue %= 1;
            }

            return(HSVColor.ToRGB(newHue, saturation, value));
        }
Пример #2
0
        public static HSVColor Lerp(HSVColor start, HSVColor end, float amount)
        {
            if (amount >= 1f)
            {
                return(new HSVColor(end));
            }
            else if (amount <= 0f)
            {
                return(new HSVColor(start));
            }

            return(new HSVColor(start.hue + (end.hue - start.hue) * amount,
                                start.saturation + (end.saturation - start.saturation) * amount,
                                start.value + (end.value - start.value) * amount,
                                start.alpha + (end.alpha - start.alpha) * amount
                                ));
        }
Пример #3
0
        public override void OnGUI(Rect pos, SerializedProperty prop, GUIContent label)
        {
            SerializedProperty hue        = prop.FindPropertyRelative("hue");
            SerializedProperty saturation = prop.FindPropertyRelative("saturation");
            SerializedProperty value      = prop.FindPropertyRelative("value");
            SerializedProperty alpha      = prop.FindPropertyRelative("alpha");

            // Using BeginProperty / EndProperty on the parent property means that
            // prefab override logic works on the entire property.
            EditorGUI.BeginProperty(pos, label, prop);

            // Draw label
            pos = EditorGUI.PrefixLabel(pos, GUIUtility.GetControlID(FocusType.Passive), label);

            // Don't make child fields be indented
            var indent = EditorGUI.indentLevel;

            EditorGUI.indentLevel = 0;

            EditorGUI.BeginChangeCheck();

            Color previousColor = HSVColor.ToRGB(hue.floatValue, saturation.floatValue, value.floatValue, alpha.floatValue);
            Color newColor      = EditorGUI.ColorField(pos, previousColor);

            // Only assign the value back if it was actually changed by the user.
            // Otherwise a single value will be assigned to all objects when multi-object editing,
            // even when the user didn't touch the control.
            if (EditorGUI.EndChangeCheck())
            {
                HSVColor newHSVColor = HSVColor.FromRGB(newColor);

                prop.FindPropertyRelative("hue").floatValue        = newHSVColor.Hue;
                prop.FindPropertyRelative("saturation").floatValue = newHSVColor.Saturation;
                prop.FindPropertyRelative("value").floatValue      = newHSVColor.Value;
                prop.FindPropertyRelative("alpha").floatValue      = newHSVColor.Alpha;
            }


            // Set indent back to what it was
            EditorGUI.indentLevel = indent;

            EditorGUI.EndProperty();
        }
Пример #4
0
 /// <summary>
 /// Generates a RGB hsvColor using random saturation and value (brightness) and specified hue and customAlpha
 /// </summary>
 /// <param name="hue">Hue of the hsvColor</param>
 /// <param name="value">Brightness of the hsvColor</param>
 /// <param name="customAlpha">Transparency: 0 = 100% transparent, 1 = 0% transparent</param>
 /// <returns>RGB hsvColor</returns>
 public static Color WithHueValue(float hue, float value, float alpha = 1)
 {
     return(HSVColor.ToRGB(hue, UnityEngine.Random.value, value, alpha));
 }
Пример #5
0
 /// <summary>
 /// Generates a RGB hsvColor using random saturation and value (brightness) and specified hue and customAlpha
 /// </summary>
 /// <param name="hue">Hue of the hsvColor</param>
 /// <param name="saturation">Saturation of the hsvColor</param>
 /// <param name="customAlpha">Transparency: 0 = 100% transparent, 1 = 0% transparent</param>
 /// <returns>RGB hsvColor</returns>
 public static Color WithHueSaturation(float hue, float saturation, float alpha = 1)
 {
     return(HSVColor.ToRGB(hue, saturation, UnityEngine.Random.value, alpha));
 }
Пример #6
0
 public HSVColor(Color c)
     : this(HSVColor.FromRGB(c))
 {
 }
Пример #7
0
 public HSVColor(HSVColor original)
     : this(original.hue, original.saturation, original.value, original.alpha)
 {
 }
Пример #8
0
 public static Color ToRGB(HSVColor hsvColor)
 {
     return(hsvColor.ToRGB());
 }
Пример #9
0
        //http://www.rapidtables.com/convert/hsvColor/rgb-to-hsv.htm
        /// <summary>
        /// Generates a RGB hsvColor using specified hue, saturation, value (brightness) and  hue and customAlpha
        /// </summary>
        /// <param name="hue">[0f, 360f] degrees</param>
        /// <param name="saturation">[0f, 1f]</param>
        /// <param name="value">[0f, 1f]</param>
        /// <param name="customAlpha">[0f, 1f]</param>
        /// <returns>RGB hsvColor</returns>
        public static Color ToRGB(float hue, float saturation, float value, float alpha = 1.0f) //value = brightness
        {
            HSVColor hsvColor = new HSVColor(hue, saturation, value, alpha);

            return(hsvColor.ToRGB());
        }
Пример #10
0
 public static HSVColor FromRGB(Color rgbColor)
 {
     return(HSVColor.FromRGB(rgbColor.r, rgbColor.g, rgbColor.b, rgbColor.a));
 }
Пример #11
0
 public HSVColor(HSVColor original)
     : this(original.hue, original.saturation, original.value, original.alpha)
 {
 }
Пример #12
0
 public static Color ToRGB(HSVColor hsvColor)
 {
     return hsvColor.ToRGB();
 }
Пример #13
0
 //value = brightness
 //http://www.rapidtables.com/convert/hsvColor/rgb-to-hsv.htm
 /// <summary>
 /// Generates a RGB hsvColor using specified hue, saturation, value (brightness) and  hue and customAlpha
 /// </summary>
 /// <param name="hue">[0f, 360f] degrees</param>
 /// <param name="saturation">[0f, 1f]</param>
 /// <param name="value">[0f, 1f]</param>
 /// <param name="customAlpha">[0f, 1f]</param>
 /// <returns>RGB hsvColor</returns>
 public static Color ToRGB(float hue, float saturation, float value, float alpha = 1.0f)
 {
     HSVColor hsvColor = new HSVColor(hue, saturation, value, alpha);
     return hsvColor.ToRGB();
 }
Пример #14
0
        public static HSVColor Lerp(HSVColor start, HSVColor end, float amount)
        {
            if (amount >= 1f)
                return new HSVColor(end);
            else if (amount <= 0f)
                return new HSVColor(start);

            return new HSVColor(start.hue + (end.hue - start.hue) * amount,
                                start.saturation + (end.saturation - start.saturation) * amount,
                                start.value + (end.value - start.value) * amount,
                                start.alpha + (end.alpha - start.alpha) * amount
                                );
        }