Hide
GUIColor

Change the color of the field.

Override:

  • GUIColor(EColor eColor, float alpha = 1f)

    Use EColor with custom alpha value

  • GUIColor(string hexColorOrCallback)

    Use hex color which starts with #, or use a callback, to get the color

  • GUIColor(float r, float g, float b, float a = 1f)

    Use rgb/rgba color (0-1 range)

// EColor + alpha [GUIColor(EColor.Cyan, 0.9f)] public int intField; // Hex color [GUIColor("#FFC0CB")] public string[] stringArray; // rgb/rgba [GUIColor(112 / 255f, 181 / 255f, 131 / 255f)] public GameObject lightGreen; [GUIColor(0, 136 / 255f, 247 / 255f, 0.3f)] public Transform transparentBlue; // Dynamic color of field [GUIColor("
quot;
+ nameof(dynamicColor)), Range(0, 10)] public int rangeField; public Color dynamicColor; // Dynamic color of callback. ` SaintsField can be omitted [GUIColor(nameof(DynamicColorFunc)), TextArea] public string textArea; private Color DynamicColorFunc() => dynamicColor; // validation [GUIColor("
quot;
+ nameof(ValidateColor))] public int validate; private Color ValidateColor() { const float c = 207 / 255f; return validate < 5 ? Color.red : new Color(c, c, c); }

It works with ShowInInspector, Button, InfoBox, etc. too:

[GUIColor(EColor.Gold)] [InfoBox("This is colored gold using <b><u><color=white>GUIColor</color></u></b> attribute.")] [Button] private void ButtonGold(){} [ShowInInspector] [GUIColor("#00FF00")] private int _greenInt = 42; [ShowInInspector] [GUIColor(EColor.Burlywood)] private int Calc([PropRange(0, 10)] int v) => v + Random.Range(1, 9) * 100; [ShowInInspector] [GUIColor("
quot;
+ nameof(GetColor))] [InfoBox("Dynamic callback")] private DateTime _dt; private byte _color255; private Color GetColor() { _color255 = (byte)((_color255 + 10) % 256); byte r = (byte)(_color255 * 1 % 256); byte g = (byte)((_color255 * 2 + 100) % 256); byte b = (byte)((_color255 * 3 + 100) % 256); return new Color32(r, g, b, 255); }

(UI Toolkit implementation code is partly from EditorAttributes, go give a star to them!)