在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的文本变为红色了

unity editor LabelField 设置不同的文本颜色

原文地址: https://www.cveoy.top/t/topic/fHWV 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录