Unity Editor LabelField 文本颜色设置 - 使用 GUIStyle
在 Unity Editor 中,可以使用 GUIStyle 来设置 LabelField 的文本颜色。下面是一个示例代码:
using UnityEditor;
using UnityEngine;
public class LabelFieldExample : EditorWindow
{
private GUIStyle _redStyle;
[MenuItem("Window/Label Field Example")]
private static void OpenWindow()
{
GetWindow<LabelFieldExample>("Label Field Example");
}
private void OnGUI()
{
if (_redStyle == null)
{
_redStyle = new GUIStyle(EditorStyles.label);
_redStyle.normal.textColor = Color.red;
}
EditorGUILayout.LabelField("This is a normal label field.");
EditorGUILayout.LabelField("This is a red label field.", _redStyle);
}
}
在这个示例中,我们创建了一个 GUIStyle 对象并设置了它的 normal.textColor 属性为红色。然后在 LabelField 中使用这个 GUIStyle 对象作为第二个参数,就可以让 LabelField 的文本变为红色了。
原文地址: https://www.cveoy.top/t/topic/onAA 著作权归作者所有。请勿转载和采集!