Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/unity3d/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何将所有gui元素(如标签或按钮)的文本颜色更改为白色?_C#_Unity3d - Fatal编程技术网

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

C# 如何将所有gui元素(如标签或按钮)的文本颜色更改为白色?,c#,unity3d,C#,Unity3d,这是我想从另一个项目中获得的白色、文本/字体大小和样式的示例 我想进入editorwindow背景色和屏幕截图中的白色文本颜色 我不需要一个树视图来制作这种文本。 我正在使用EditorWindow类型脚本 在顶部,我做了: private static Texture2D tex; 然后: [MenuItem(“窗口/测试”)] 静态void ShowEditor() { editor=EditorWindow.GetWindow(); editor.Init(); tex=新纹理2d(1

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

我想进入editorwindow背景色和屏幕截图中的白色文本颜色

我不需要一个树视图来制作这种文本。 我正在使用EditorWindow类型脚本

在顶部,我做了:

private static Texture2D tex;
然后:

[MenuItem(“窗口/测试”)]
静态void ShowEditor()
{
editor=EditorWindow.GetWindow();
editor.Init();
tex=新纹理2d(1,1,TextureFormat.RGBA32,false);
tex.SetPixel(0,0,彩色.黑色);
tex.Apply();
中心窗口();
}
在OnGUI内部:
void OnGUI()
{
DrawTexture(新的Rect(0,0,maxSize.x,maxSize.y),tex,ScaleMode.StretchToFill);
//标签(新的Rect(200200100100),“A标签”);
//TextField(新的Rect(20,20,70,30),“”);
GUIStyle itemStyle=new GUIStyle();//创建一个新的GUIStyle
itemStyle.alignment=TextAnchor.Middleft;//将文本向左对齐
itemStyle.active.background=itemStyle.normal.background;//删除按钮单击背景样式。
itemStyle.margin=新的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。添加此选项应使所有具有此样式的文本变为白色

我认为
itemStyle.normal.textColor=Color.white
应该可以做到。@mayo仍然不起作用。所有元素的文本和字体(如标签按钮)都是黑色的;您在使用之前是否设置了样式
private void OnGUI(){var rect=new rect(10,10,Screen.width,Screen.height);var labelText=“示例”;var style=new GUIStyle();style.normal.textColor=Color.red;GUI.Label(rect,labelText,style);}
    [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;
    }