2
\$\begingroup\$

Writing an asset management GUI as part of our editor tools, I am in some places colouring LabelFields. Working mostly in the dark Pro skin, this seems to work just fine:

GUI.color = Color.green;         
EditorGUILayout.LabelField("Name", GUILayout.Width(75f));
GUI.color = Color.white;

When switching to the light default skin however, this colouring is no longer visible. The usual GUI.backgroundColor still functions fine there as it does in the dark skin.

Is this "foreground" colour something specific to the dark Pro skin? If so, is there perhaps another way to achieve a similar effect?

\$\endgroup\$
1
+50
\$\begingroup\$

No, foregroundColor is not specific to Pro skin: it's just that font color in light skin is black.

The way GUI.foregroundColor (and all other colors in GUI) works is that it's multiplied by whatever color is drawn. But black multiplied by anything stays black, so the setting appears to have no effect.

Fortunately, there are pre-defined editor styles that use white font color in any skin. Use this line:

GUI.color = Color.green;         
EditorGUILayout.LabelField("Name", EditorStyles.whiteLabel, GUILayout.Width(75f));
GUI.color = Color.white;

By the way, in Light skin default GUI.color is not white, but some kind of gray, I don't know exact RGB values. So to restore default look, you should save this value and restore it later, not just set color to white.

\$\endgroup\$
  • \$\begingroup\$ Oh geez...and here I was thinking "hmm, my colors look muddy in the Pro skin. They must be multiplying them...". Tested and it works. Thank you ever so much. (p.s. you'll get the bounty once I can award it ;) ) \$\endgroup\$ – Bart Mar 8 '13 at 11:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.