Why not let all color pickers values to 0 to 1?

Right now, only the HDR color pickers shows Color values instead of Color32, since Color is kinda the default when coding, why not let all color pickers (materials colors, light colors, hdr colors, etc) to display 0 to 1? Or, for non hdr colors, let us choose to display between 0 to 1 or 0 to 255 in the color picker window.

Thanks in advance

Not sure if Windows has the same option, but on a Mac, you can set in the preferences to use OSX color picker, and that has a ton of options.

2 Likes

That’s awesome! But we don’t have that in the windows version, at least I couldn’t find it…
Even if we could use the OS’s color picker… windows’ color picker is the worst, we can’t adjust the alpha value and we only have the 0 to 255 option.

Another option is that you can extend the color color selector, (in editor), there is an asset that does it, but I can’t recall or find it.

I’m not sure what you need if for specifically, but I wrote a property drawer a while ago that provides the values as a textfield string, primarily for getting color vals for editor scripts and source. I did quick modification to it so you can set the rgba vals in the inspector.

Attribute (ColorHelper.cs) :
ColorHelper.cs

// -----------------------------------------------------------------------
//  <contact>https://github.com/ZombieGorilla/EditorTools</contact>
//    <description>Inspector Color Helper Attribute</description>
//    <version>2.0.0</version>
// -----------------------------------------------------------------------

using UnityEngine;
using System;

public class ColorHelper : PropertyAttribute
{
    public int display_option = 0;
   
    public ColorHelper () { }
   
    public ColorHelper (int display_op) 
    {
        this.display_option = display_op;
    }
   
    public ColorHelper (string display_op) 
    {
        display_op = display_op.ToLower();
        switch (display_op) 
        {
            case "select": this.display_option = 0; break;
            case "values": this.display_option = 1; break;
            case "alpha": this.display_option = 2; break;
            case "rgba": this.display_option = 3; break;
            case "saturation": this.display_option = 4; break;
        }
    }
}

Drawer (ColorHelperDrawer.cs) :
ColorHelperDrawer.cs

// -----------------------------------------------------------------------
//  <contact>https://github.com/ZombieGorilla/EditorTools</contact>
//    <description>Inspector Color Helper Drawer</description>
//    <version>2.0.1</version>
// -----------------------------------------------------------------------

using UnityEditor;
using UnityEngine;

[CustomPropertyDrawer(typeof(ColorHelper))]
public class ColorHelperDrawer : PropertyDrawer
{
    ColorHelper color_helper { get { return ((ColorHelper) attribute); } }
    string[] options = new string[] {"Select", "Values", "Alpha", "RGBA", "Saturation"};
   
    // layout settings
    float popup_width = 70f;
    float base_height = 0f;
    float gap = 3f;
    float margin_bottom = 3f;
    float margin = 2f;
    float swatch_margin = 2f;
    float swatch_width = 12f;


    public override float GetPropertyHeight (SerializedProperty property, GUIContent label) 
    {
        base_height = base.GetPropertyHeight(property, label);
        float h = (color_helper.display_option==3) ? base_height*5 : (color_helper.display_option==0) ? base_height : base_height*2;
        return h+margin_bottom+margin+margin;
    }


    public override void OnGUI (Rect position, SerializedProperty property, GUIContent label) 
    {
        Rect contentPosition = EditorGUI.PrefixLabel(position, label);
            contentPosition.y+=margin;
            contentPosition.height=base_height;
            contentPosition.x+=margin;
            contentPosition.width -= (margin*2);
           
        // draw background
        Rect bkg = EditorGUI.PrefixLabel(position, label);
            bkg.height-=margin_bottom;

        GUI.Box(bkg, "", new GUIStyle("ShurikenEffectBg"));           
       
        // main block
        label = EditorGUI.BeginProperty(position, label, property);
       
        // color field
        Rect main_cont = contentPosition;
            main_cont.x+=popup_width; 
            main_cont.width-=(popup_width);
       
        EditorGUI.indentLevel = 0;
        EditorGUI.PropertyField(main_cont, property, GUIContent.none);
       
       
        // selection popup
        Rect popupPosition = contentPosition;
            popupPosition.width = popup_width-gap;
       
       color_helper.display_option = EditorGUI.Popup(popupPosition,color_helper.display_option,options);
       
        // content
        contentPosition.y +=base_height;
       
        Rect swatchPosition = contentPosition;
            swatchPosition.x = contentPosition.width+contentPosition.x - swatch_width;
            swatchPosition.width = swatch_width;
       
        Color c = property.colorValue;

        switch (color_helper.display_option) 
        {
            case 1: // value string
            {
                EditorGUI.TextField(contentPosition, c.r+","+c.g+","+c.b+","+c.a );   
                break;
            }
            case 2:  // alpha slider
            {
                contentPosition.width -= (swatch_width+gap);
                c.a = ColorSlider(c, contentPosition, 3,false);
                property.colorValue = c;
                break;
            }
            case 3: // RGBA
            {
                contentPosition.width -= (swatch_width+gap);
                c.r = ColorSlider(c, contentPosition, 0);
                c.g = ColorSlider(c, contentPosition, 1);
                c.b = ColorSlider(c, contentPosition, 2);
                c.a = ColorSlider(c, contentPosition, 3);
                property.colorValue = c;
                break;
            }
            case 4: // Saturation
            {
                contentPosition.width -= (swatch_width+gap);
                property.colorValue = SaturationSlider(c, contentPosition);
                break;
            }
        }
        EditorGUI.EndProperty();
    }
   
   
    float ColorSlider(Color c, Rect base_pos, int pos) { return ColorSlider(c, base_pos, pos, true); }
    float ColorSlider(Color c, Rect base_pos, int index, bool use_pos)
    {
        if(use_pos) base_pos.y+=(index*base_height);
        float cv = DrawSlider(c[index],base_pos);
        if(index != 3)
        {
            c=Color.black;
            c[index] = cv;
        }
        DrawSwatch(c,base_pos);
        return cv;
    }
   
   
    Color SaturationSlider(Color c, Rect base_pos)
    {
        float s,v,h;
        Color.RGBToHSV(c, out h, out s, out v);
        s = DrawSlider(s,base_pos, 0.00001f);
        c =  Color.HSVToRGB(h,s,v);
        DrawSwatch(c,base_pos);
        return c;
    }
   
   
    float DrawSlider(float v, Rect base_pos) { return DrawSlider(v,base_pos,0f); }
    float DrawSlider(float v, Rect base_pos, float min)
    {
        base_pos.x+=2; // fix odd positioning for slider
        return EditorGUI.Slider(base_pos, v, min, 1f);
    }
   
   
    void DrawSwatch(Color c, Rect base_pos)
    {
        base_pos.x =  base_pos.x+base_pos.width+gap+swatch_margin-1;
        base_pos.y +=  swatch_margin-1;
        base_pos.width = swatch_width-(swatch_margin*2);
        base_pos.height -= (swatch_margin*2)+1;
       
        GUIStyle g = new GUIStyle("ProfilerTimelineBar");
            g.margin = new RectOffset(0,0,0,0);
            g.padding = new RectOffset(0,0,0,0);
       
        GUI.color = c;
        GUI.Box(base_pos, "",g);
        GUI.color = Color.white;
    }
}

Usage Example :
Usage Example

    [Header("Color Helper Examples")]
   
    [ColorHelper()] // or [ColorHelper("Select")] or [ColorHelper(0)]  
    [SerializeField] public Color OptionSelect;
   
    [ColorHelper("Values")] // or [ColorHelper(1)] 
    [SerializeField] public Color OptionValues;
   
    [ColorHelper("Alpha")] // or [ColorHelper(2)] 
    [SerializeField] public Color OptionAlpha;
   
    [ColorHelper("RGBA")] // or [ColorHelper(3)] 
    [SerializeField] public Color OptionRGBA;
   
    [ColorHelper("Saturation")] // or [ColorHelper(4)] 
    [SerializeField] public Color OptionSaturation;

1 Like

Very nice! Thanks a lot for that, very useful!
I made some searches on the asset store but couldn’t find any color picker as editor extension, only in-game color pickers, but it’s okay, I will send them a suggestion in the feedback site, it’s not road blocking after all, it would just be nice to have a more abravise color picker, with more options, I also think that there is no point in only showing RGBA or HSV separated, needing to click somewhere to switch between modes.

Anyway, thanks for the replies @zombiegorilla !

1 Like

I might be wrong here, but can’t you just take the 0-1 value you want and multiply it by 255?

For example, if you need 0.6 you’d type in 153. Maybe I’m missing something here.

I’ve dropped feedback in the Feedback Hub app for Windows to improve the OS color mixer, but Microsoft is probably not very concerned with that since it now takes a registry hack to bring back the custom system color maker we’ve had since Vista, which in 10 was replaced by a grid of pre-made colors.

In the meantime, couldn’t Unity make a custom color picker, or improve the existing one?

1 Like

Yes, I could do that, in my case I need to do the inverse, divide the 0-255 values by 255 because I prefer to work with 0-1 values, I was just suggesting that they only use the normalized values for convenience.
In the editor I was tweaking a scene lighting (tweaking values of scene lights and the ambient light) and I just found that the ambient light color picker shows normalized values (because of the HDR I think) while the light components shows 0-255 values.

Yes, my suggestion is that they improve the current color picker, I would prefer to only have 0-1 values in the color picker, but they could also offer a way to switch between the two modes because some people prefer to work with 0-255 values…

1 Like

Yea, whenever working with code, the values are normalized. Honestly, it would make sense that it only used 0-1. I too would prefer an improved color picker, at least one that was more relevant to Unity development. I have had to make several different color tools for our artists to use. The one in editor now is pretty much the bare minimum to qualify as a color picker. :wink: . My suspicion is that it won’t improve anytime in near future, I would guess it is pretty low priority because it does function, and most detailed color work is going to be done in external tools. Sucks, but it is what it is, I just to try to improve my own usability via the editor.

1 Like