繁体   English   中英

如何更改所有GUI元素(如标签或按钮)的文本颜色,或仅将文本更改为白色?

[英]How can I change the text color of all gui elements like labels or buttons or just text to white color?

这是我想从另一个项目中获得的白色,文本/字体大小和样式的示例。

例

我想像在屏幕截图中那样获得editorwindow背景颜色和白色文本颜色。

我不需要树状视图即可生成此类文本。 我正在使用EditorWindow类型的脚本。

在顶部,我做了:

private static Texture2D tex;

然后:

    [MenuItem("Window/Test")]
        static void ShowEditor()
        {
            editor = EditorWindow.GetWindow<Test>();
            editor.Init();

            tex = new Texture2D(1, 1, TextureFormat.RGBA32, false);
            tex.SetPixel(0, 0, Color.black);
            tex.Apply();

            CenterWindow();
        }

And inside the OnGUI:

void OnGUI()
    {
        GUI.DrawTexture(new Rect(0, 0, maxSize.x, maxSize.y), tex, ScaleMode.StretchToFill);
        //GUI.Label(new Rect(200, 200, 100, 100), "A label");
        //GUI.TextField(new Rect(20, 20, 70, 30), "");

        GUIStyle itemStyle = new GUIStyle();  //make a new GUIStyle

        itemStyle.alignment = TextAnchor.MiddleLeft; //align text to the left
        itemStyle.active.background = itemStyle.normal.background;  //gets rid of button click background style.
        itemStyle.margin = new RectOffset(0, 0, 0, 0);
        GUI.backgroundColor = Color.white;
        GUI.skin.toggle.fontStyle = FontStyle.Normal;
        GUI.skin.toggle.fontSize = 13;
    }

但这并没有太大变化。 它以黑色绘制整个窗口并将其着色,但gui元素的元素却不是白色,如屏幕截图示例中所示。

您缺少itemStyle.normal.textColor = Color.white; 添加此选项应使具有此样式的所有文本变为白色

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM