ColorField
示例程序 | |
---|---|
说明 | 生成控制颜色类 Color 的区域 |
用法
public static Color ColorField(Color value, params GUILayoutOption[] options);
public static Color ColorField(string label, Color value, params GUILayoutOption[] options);
public static Color ColorField(GUIContent label, Color value, params GUILayoutOption[] options);
public static Color ColorField(GUIContent label, Color value, bool showEyedropper, bool showAlpha, bool hdr, params GUILayoutOption[] options);
参数
label
对应的标签名称。
value
该区域控制的颜色变量。
showEyedropper
是否添加取色器工具。
showAlpha
是否添加透明度通道。
hdr
取值为 true
时视为 HDR 颜色值,否则视为普通 LDR 颜色值。
options
(可选)用于指定额外的布局属性,该参数将覆盖默认样式。
示例
public override void OnInspectorGUI () {
// First reload, no label, no extra options
_target.ColorFirst = EditorGUILayout.ColorField (_target.ColorFirst);
// Second reload, with a label and an expanded width
_target.ColorSecond = EditorGUILayout.ColorField ("Color Second", _target.ColorSecond, GUILayout.ExpandWidth (true));
// Third reload, with a label, a tooltip and a set of options
var guiContent = new GUIContent ("Color Third", "This is the third color picker.");
var guiLayoutOptions = new GUILayoutOption [] {
GUILayout.ExpandWidth(false),
GUILayout.MinWidth(200)
};
_target.ColorThird = EditorGUILayout.ColorField (guiContent, _target.ColorThird, guiLayoutOptions);
// Forth reload, with no eyedropper, no alpha, in HDR mode
guiContent = new GUIContent ("Color Forth", "This is the forth color picker.");
guiLayoutOptions = new GUILayoutOption [] {
GUILayout.ExpandWidth(true),
GUILayout.Height(200)
};
_target.ColorForth = EditorGUILayout.ColorField (guiContent, _target.ColorForth, false, false, true, guiLayoutOptions);
}
编译结果如下: