如何在Unity Editor中为PrefixLabel着色? [英] How can I color a PrefixLabel in Unity Editor?
问题描述
我的问题很简单:我只想能够使用 EditorGUILayout.PrefixLabel
,但将文本颜色更改为白色.
My question is that simple: I just want to be able to use EditorGUILayout.PrefixLabel
but change the text color to white.
但是到目前为止,我还没有运气.
我可以轻松更改所有其他元素的颜色,但是对于PrefixLabel
来说,什么都没有起作用.
我想坚持使用PrefixLabel
,因为它可以减少所有标签和字段排列的代码量.
But so far I have no luck.
I can easely change the color of all other elements but for the PrefixLabel
nothing is working.
I want to stick with PrefixLabel
since it simply is less code to have all labels and fields arranged well.
到目前为止我尝试过的一些事情:
A fiew things I tried so far:
使用 EditorStyles.label.normal.textColor
var old = EditorStyles.label.normal.textColor;
EditorStyles.label.normal.textColor = Color.white;
EditorGUILayout.PrefixLabel("label Text");
EditorStyles.label.normal.textColor = old;
另外应用new GUIStyle(EditorStyles.label)
var old = EditorStyles.label.normal.textColor;
EditorStyles.label.normal.textColor = Color.white;
EditorGUILayout.PrefixLabel("label Text", new GUIStyle(EditorStyles.label));
EditorStyles.label.normal.textColor = old;
EditorGUILayout.PrefixLabel("label Text", new GUIStyle(EditorStyles.whiteLabel));
var old = GUI.contentColor;
EditorStyles.label.normal.textColor = Color.white;
EditorGUILayout.PrefixLabel("label Text");
GUI.contentColor = old;
使用GUI.skin.label.normal.textColor
var old = GUI.skin.label.normal.textColor;
GUI.skin.label.normal.textColor = Color.white;
EditorGUILayout.PrefixLabel("label Text");
GUI.skin.label.normal.textColor = old;
使用 new GUIStyle
whiteTextStyle = new GUIStyle(EditorStyles.label)
{
normal = {
textColor = Color.white;
}
};
EditorGUILayout.PrefixLabel("label Text", whiteTextStyle);
是否有其他提示我可以尝试?
推荐答案
EditorStyles.label.normal.textColor
本来可以使用,但是由于未绘制PrefixLabel,我不得不在EditorGUILayout.XYField
之后 重置颜色.直到现场通话.
EditorStyles.label.normal.textColor
would already have worked but I had to reset the color back after the EditorGUILayout.XYField
because the PrefixLabel was not drawed until the field call.
var old = EditorStyles.label.normal.textColor;
EditorStyles.label.normal.textColor = Color.white;
EditorGUILayout.PrefixLabel("label Text");
EditorGUILayout.IntField(5);
EditorStyles.label.normal.textColor = old;
这篇关于如何在Unity Editor中为PrefixLabel着色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!