简体   繁体   English

如何在EditorWindow脚本中加粗EditorGUILayout.Toggle?

[英]How can I bold a EditorGUILayout.Toggle in EditorWindow script?

Before I asked about how to bold a GUI.Toggle The answer was to create a style: 在我问如何加粗GUI之前,答案是创建样式:

GUIStyle myToggleStyle = new GUIStyle(GUI.skin.toggle);

Then set it to bold: 然后将其设置为粗体:

myToggleStyle.fontStyle = FontStyle.Bold;

And last use it with the Toggle: 最后将它与Toggle一起使用:

GUI.Toggle(new Rect(5, 10, 200, 60), false, "Select All", myToggleStyle);

But now I'm using another Toggle with the same text "Select All" but this time it's EditorGILayout.Toggle and I don't need or want to use GUI.Toggle since GUI.Toggle need a Rect. 但是现在我正在使用另一个具有相同文本“全选”的Toggle,但这一次是EditorGILayout.Toggle,我不需要或不想使用GUI.Toggle,因为GUI.Toggle需要Rect。

The problem is that with EditorGUILayout.Toggle the myToggleStyle is not working. 问题在于使用EditorGUILayout.Toggle myToggleStyle无法正常工作。 It does nothing and not making the text/font to be bold. 它什么也不做,不会使文本/字体变粗体。

This is inside the OnGUI: 这是在OnGUI内部:

EditorGUI.BeginChangeCheck();
selectAll[i] = EditorGUILayout.Toggle("Select All", selectAll[i]);
if (EditorGUI.EndChangeCheck())
              SelectDeselectAll(i);

I tried this: 我尝试了这个:

EditorGUI.BeginChangeCheck();
GUIStyle myToggleStyle = new GUIStyle(GUI.skin.toggle);
myToggleStyle.fontStyle = FontStyle.Bold;
selectAll[i] = EditorGUILayout.Toggle("Select All", selectAll[i], myToggleStyle);
if (EditorGUI.EndChangeCheck())
    SelectDeselectAll(i);

But it's not making the "Select All" bold. 但这并没有使“全选”加粗。

A working Solution: 一个可行的解决方案:

EditorGUI.BeginChangeCheck();
var origFontStyle = EditorStyles.label.fontStyle;
EditorStyles.label.fontStyle = FontStyle.Bold;
selectAll[i] = EditorGUILayout.Toggle("Select All", selectAll[i]);
EditorStyles.label.fontStyle = origFontStyle;
if (EditorGUI.EndChangeCheck())
    SelectDeselectAll(i);

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

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