EditorGUILayout.ColorField 是 Unity 编辑器中用于绘制和编辑 Color 类型字段的控件。它提供了一个颜色选择器,允许用户通过 GUI 直接选择和调整颜色。
using UnityEditor;
using UnityEngine;
public class ColorFieldExample : EditorWindow
{
private Color colorValue = Color.white;
[MenuItem("Window/Color Field Example")]
public static void ShowWindow()
{
GetWindow<ColorFieldExample>("Color Field Example");
}
private void OnGUI()
{
GUILayout.Label("Color Field Example", EditorStyles.boldLabel);
colorValue = EditorGUILayout.ColorField("Select Color", colorValue);
GUILayout.Label($"Selected Color: {colorValue}");
Rect colorRect = GUILayoutUtility.GetRect(100, 50);
EditorGUI.DrawRect(colorRect, colorValue);
}
}
运行效果