示例#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 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();
        }
示例#3
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));
 }
示例#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="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));
 }
示例#5
0
 public static Color ToRGB(HSVColor hsvColor)
 {
     return(hsvColor.ToRGB());
 }
示例#6
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());
        }
示例#7
0
 public static Color ToRGB(HSVColor hsvColor)
 {
     return hsvColor.ToRGB();
 }
示例#8
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();
 }