Select Page

Today, when I was working on my personal project, I needed to pick and edit a color, also I needed the other color representations like Hexadecimal and RGBA, so for doing this, I needed to open a external program to pick and edit colors, but I got tired by doing this every time and decided to create a small utility window for Unity for color picking and editing, and now it is alive.

Color Picker Utility Window

Color Picker Utility Window

Installation

The installation is very simple, just follow the below steps:

  1. Download or Copy/Paste the script inside a Editor folder, like Assets/Editor folder.
  2. Navigate to Tools > Color Picker menu to open the Color Picker window.
  3. You are ready to go!

Features

  • RGBA editing with Sliders
  • Hex Code
  • Color and Color32 C# code
  • Color Picker for picking colors inside or outside Unity

Resources

Try your best to enjoy it!
Thanks.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;

public class ColorPickerWindow : EditorWindow
{

    protected Color color = Color.white;
    protected Color32 color32 = new Color32 ( 255, 255, 255, 255 );
    protected string hexCode = "FFFFFF";

    [MenuItem ( "Tools/Color Picker" )]
    public static void Init ()
    {
        var window = EditorWindow.GetWindow<ColorPickerWindow> ( "Color Picker" );
        window.Show ();
    }

    protected virtual void OnGUI ()
    {
        this.color = EditorGUILayout.ColorField ( "Color", this.color );
        if ( GUI.changed )
        {
            this.color32 = this.color;
            this.hexCode = ColorUtility.ToHtmlStringRGB ( this.color );
        }
        this.hexCode = EditorGUILayout.TextField ( "Hex Code", this.hexCode );
        if ( GUI.changed )
        {
            ColorUtility.TryParseHtmlString ( this.hexCode, out this.color );
        }
        this.color32.r = ( byte )EditorGUILayout.IntSlider ( "Red", this.color32.r, 0, 255 );
        this.color32.g = ( byte )EditorGUILayout.IntSlider ( "Green", this.color32.g, 0, 255 );
        this.color32.b = ( byte )EditorGUILayout.IntSlider ( "Blue", this.color32.b, 0, 255 );
        this.color32.a = ( byte )EditorGUILayout.IntSlider ( "Alpha", this.color32.a, 0, 255 );
        if ( GUI.changed )
        {
            this.color = this.color32;
            this.hexCode = ColorUtility.ToHtmlStringRGB ( this.color );
        }
        EditorGUILayout.TextField (
            "Color Code",
            string.Format (
                "new Color ( {0}f, {1}f, {2}f, {3}f )",
                this.color.r,
                this.color.g,
                this.color.b,
                this.color.a ) );
        EditorGUILayout.TextField (
            "Color32 Code",
            string.Format (
                "new Color32 ( {0}, {1}, {2}, {3} )",
                this.color32.r,
                this.color32.g,
                this.color32.b,
                this.color32.a ) );
    }
    
}