/// <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)); }
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 )); }
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(); }
/// <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)); }
/// <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)); }
public HSVColor(Color c) : this(HSVColor.FromRGB(c)) { }
public HSVColor(HSVColor original) : this(original.hue, original.saturation, original.value, original.alpha) { }
public static Color ToRGB(HSVColor hsvColor) { return(hsvColor.ToRGB()); }
//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()); }
public static HSVColor FromRGB(Color rgbColor) { return(HSVColor.FromRGB(rgbColor.r, rgbColor.g, rgbColor.b, rgbColor.a)); }
public static Color ToRGB(HSVColor hsvColor) { return hsvColor.ToRGB(); }
//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(); }
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 ); }