public void CopyFrom(Color c) { HSVColor hsv = HSVColor.FromRGB(c); hue = hsv.Hue; saturation = hsv.Saturation; value = hsv.Value; alpha = hsv.Alpha; }
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(); }
public HSVColor(Color c) : this(HSVColor.FromRGB(c)) { }
public static HSVColor FromRGB(Color rgbColor) { return(HSVColor.FromRGB(rgbColor.r, rgbColor.g, rgbColor.b, rgbColor.a)); }