c# - 如何将所有 gui 元素(如标签或按钮)的文本颜色更改为白色?
问题描述
这是我想在我的项目中从另一个项目中获取的白色和文本/字体大小和样式的示例。
我想进入编辑器窗口背景颜色和屏幕截图中的白色文本颜色。
我不需要树视图来制作这种文本。我正在使用 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;
。添加这个应该会使所有具有这种样式的文本变成白色
推荐阅读
- r - R CMD Check, '--no-manual': 如何改变这个选项?
- r - 如何仅访问不同列中给定条件的列信息
- c - 如何在一个变量中使用 OCIBindDynamic 来输入/输出?
- python - 如何为大型 xbrl 文件设置 arelle?
- javascript - 选项卡聚焦时未调用firebase onMessage
- android - 如何使父 ViewGroup 居中?
- ssh - 如果我可以在本地,为什么我不能通过 SSH 使用远程客户端访问 MariaDB?
- groovy - 使用 jar 文件 + 动态值进入循环计数器 - Jmeter
- soap - webMethods 6.5 中的 SOAP 错误“iaik.security.ssl.SSLException: Peer sent alert: Alert Fatal: handshake failure”
- r - 使用引导、分类变量的分位数回归的置信区间