Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
A Color Picker Window for Unity

Color Picker

A Color Picker utility window for Unity.

Deprecation Notice

This gist is deprecated due to release of this utility on Asset Store, you can now get the latest version of this utility from Asset Store, but it is available here as is without any updates.

Features

  • RGBA editing
  • Hex Code
  • Color & Color32 C# Code
  • Color Picker

Screenshots

Color Picker Window

Installation

  • Download or Copy/Pase the Script
  • Put it in a Editor folder inside your Unity project
  • Navigate to the Tools > Color Picker menu
  • You are ready to go!

Resources

License

MIT @ Hasan Bayat

Made with ❤️ by Hasan Bayat

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 ) );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.