EditorGUI 和 EditorGUILayout 对比

本文详细介绍了Unity编辑器中GUI系统的各个组件及其用法,包括静态属性与方法,如EditorGUI和EditorGUILayout的相关函数,例如ColorField、IntField等,并探讨了如何使用这些工具来定制编辑器界面。

静态属性

EditorGUIEditorGUILayout
actionKeyx
indentLevelx
showMixedValuex

静态方法

EditorGUIEditorGUILayout
xBeginFadeGroup / EndFadeGroup
xBeginHorizontal / EndHorizontal
xBeginScrollView / EndScrollView
xBeginToggleGroup / EndToggleGroup
xBeginVertical / EndVertical
BegineChangeCheck / EndChangeCheckx
BeginDisabledGroup / EndDisabledGroupx
BeginProperty / EndPropertyx
BoundsField
BoundsIntField
CanCacheInspectorGUIx
ColorField
CurveField
DelayedDoubleField
DelayedFloatField
DelayedIntField
DelayedTextField
DoubleField
DropdownButton
DrawPreviewTexturex
DrawRectx
DrawTextureAlphax
DropShadowLabelx
EnumFlagsField
EnumPopup
FloatField
FocusTextInControlx
Foldout
xGetControlRect
GetPropertyHeightx
HandlePrefixLabelx
HelpBox
InspectorTitlebar
IntField
IntPopup
IntSlider
LabelField
LayerField
LongField
MaskField
MinMaxSlider
MultiFloatFieldx
MultiIntFieldx
MultiPropertyFieldx
ObjectField
PasswordField
Popup
PrefixLabel
ProgressBarx
PropertyField
RectField
RectIntField
SelectableLabel
Slider
xSpace
TagField
TextArea
TextField
Toggle
ToggleLeft
Vector2Field
Vector2IntField
Vector3Field
Vector3IntField
Vector4Field
HSVFoldout = EditorGUILayout.BeginFoldoutHeaderGroup(HSVFoldout, "HSV变化功能"); if (HSVFoldout) { EditorGUI.indentLevel++; globalFoldout = EditorGUILayout.BeginFoldoutHeaderGroup(globalFoldout, "全局通道"); if (globalFoldout) { EditorGUI.indentLevel++; using (new EditorGUILayout.VerticalScope("helpbox")) { string str = "全局色相偏移"; materialEditor.ShaderProperty(_props.GlobalHueShift, new GUIContent(str)); } using (new EditorGUILayout.VerticalScope("helpbox")) { string str = "全局对比度"; materialEditor.ShaderProperty(_props.GlobalSaturation, new GUIContent(str)); } using (new EditorGUILayout.VerticalScope("helpbox")) { string str = "全局亮度"; materialEditor.ShaderProperty(_props.GlobalValue, new GUIContent(str)); } EditorGUI.indentLevel--; } EditorGUI.indentLevel--; using (new EditorGUILayout.VerticalScope("helpbox")) { GUILayout.Label("红色通道"); using (new EditorGUILayout.VerticalScope("helpbox")) { using (new EditorGUILayout.VerticalScope("helpbox")) { string str = "红色色相偏移"; materialEditor.ShaderProperty(_props.RedHueShift, new GUIContent(str)); } using (new EditorGUILayout.VerticalScope("helpbox")) { string str = "红色对比度"; materialEditor.ShaderProperty(_props.RedSaturation, new GUIContent(str)); } using (new EditorGUILayout.VerticalScope("helpbox")) { string str = "红色亮度"; materialEditor.ShaderProperty(_props.RedValue, new GUIContent(str)); } using (new EditorGUILayout.VerticalScope("helpbox")) { string str = "红色色相偏移范围"; materialEditor.ShaderProperty(_props.RedRange, new GUIContent(str)); } } } using (new EditorGUILayout.VerticalScope("helpbox")) { GUILayout.Label("黄色通道"); using (new EditorGUILayout.VerticalScope("helpbox")) { using (new EditorGUILayout.VerticalScope("helpbox")) { string str = "黄色色相偏移"; materialEditor.ShaderProperty(_props.YellowHueShift, new GUIContent(str)); } using (new EditorGUILayout.VerticalScope("helpbox")) { string str = "黄色对比度"; materialEditor.ShaderProperty(_props.YellowSaturation, new GUIContent(str)); } using (new EditorGUILayout.VerticalScope("helpbox")) { string str = "黄色亮度"; materialEditor.ShaderProperty(_props.YellowValue, new GUIContent(str)); } using (new EditorGUILayout.VerticalScope("helpbox")) { string str = "黄色色相偏移范围"; materialEditor.ShaderProperty(_props.YellowRange, new GUIContent(str)); } } } using (new EditorGUILayout.VerticalScope("helpbox")) { GUILayout.Label("绿色通道"); using (new EditorGUILayout.VerticalScope("helpbox")) { using (new EditorGUILayout.VerticalScope("helpbox")) { string str = "绿色色相偏移"; materialEditor.ShaderProperty(_props.GreenHueShift, new GUIContent(str)); } using (new EditorGUILayout.VerticalScope("helpbox")) { string str = "绿色对比度"; materialEditor.ShaderProperty(_props.GreenSaturation, new GUIContent(str)); } using (new EditorGUILayout.VerticalScope("helpbox")) { string str = "绿色亮度"; materialEditor.ShaderProperty(_props.GreenValue, new GUIContent(str)); } using (new EditorGUILayout.VerticalScope("helpbox")) { string str = "绿色色相偏移范围"; materialEditor.ShaderProperty(_props.GreenRange, new GUIContent(str)); } } } using (new EditorGUILayout.VerticalScope("helpbox")) { GUILayout.Label("靛青色通道"); using (new EditorGUILayout.VerticalScope("helpbox")) { using (new EditorGUILayout.VerticalScope("helpbox")) { string str = "靛青色相偏移"; materialEditor.ShaderProperty(_props.CyanHueShift, new GUIContent(str)); } using (new EditorGUILayout.VerticalScope("helpbox")) { string str = "靛青对比度"; materialEditor.ShaderProperty(_props.CyanSaturation, new GUIContent(str)); } using (new EditorGUILayout.VerticalScope("helpbox")) { string str = "靛青亮度"; materialEditor.ShaderProperty(_props.CyanValue, new GUIContent(str)); } using (new EditorGUILayout.VerticalScope("helpbox")) { string str = "靛青色相偏移范围"; materialEditor.ShaderProperty(_props.CyanRange, new GUIContent(str)); } } } using (new EditorGUILayout.VerticalScope("helpbox")) { GUILayout.Label("蓝色通道"); using (new EditorGUILayout.VerticalScope("helpbox")) { using (new EditorGUILayout.VerticalScope("helpbox")) { string str = "蓝色色相偏移"; materialEditor.ShaderProperty(_props.BlueHueShift, new GUIContent(str)); } using (new EditorGUILayout.VerticalScope("helpbox")) { string str = "蓝色对比度"; materialEditor.ShaderProperty(_props.BlueSaturation, new GUIContent(str)); } using (new EditorGUILayout.VerticalScope("helpbox")) { string str = "蓝色亮度"; materialEditor.ShaderProperty(_props.BlueValue, new GUIContent(str)); } using (new EditorGUILayout.VerticalScope("helpbox")) { string str = "蓝色色相偏移范围"; materialEditor.ShaderProperty(_props.BlueRange, new GUIContent(str)); } } } using (new EditorGUILayout.VerticalScope("helpbox")) { GUILayout.Label("品红色通道"); using (new EditorGUILayout.VerticalScope("helpbox")) { using (new EditorGUILayout.VerticalScope("helpbox")) { string str = "品红色色相偏移"; materialEditor.ShaderProperty(_props.MagentaHueShift, new GUIContent(str)); } using (new EditorGUILayout.VerticalScope("helpbox")) { string str = "品红色对比度"; materialEditor.ShaderProperty(_props.MagentaSaturation, new GUIContent(str)); } using (new EditorGUILayout.VerticalScope("helpbox")) { string str = "品红色亮度"; materialEditor.ShaderProperty(_props.MagentaValue, new GUIContent(str)); } using (new EditorGUILayout.VerticalScope("helpbox")) { string str = "品红色色相偏移范围"; materialEditor.ShaderProperty(_props.MagentaRange, new GUIContent(str)); } } } } EditorGUILayout.EndFoldoutHeaderGroup(); }
08-27
### 关于 `EditorGUILayout` 的使用教程 #### 什么是 `EditorGUILayout` `EditorGUILayout` 是 Unity 中用于创建自定义编辑器窗口 Inspector 面板的一个类。它提供了许多静态方法来布局显示各种 UI 控件,这些控件能够响应用户的输入并更新序列化的对象属性。 #### 基本用法 为了展示如何利用 `EditorGUILayout` 创建一个简单的自定义 Inspector,下面是一个例子: ```csharp using UnityEngine; using UnityEditor; public class CustomInspectorExample : Editor { SerializedProperty m_Prop; void OnEnable() { m_Prop = serializedObject.FindProperty("myCustomField"); } public override void OnInspectorGUI() { // 更新SerializedObject的状态到最新的数据 serializedObject.Update(); // 开始更改检测 EditorGUI.BeginChangeCheck(); // 显示属性字段,并提供标签文本 EditorGUILayout.PropertyField(m_Prop, new GUIContent("我的自定义字段")); // 如果发生改变,则处理变化后的逻辑 if (EditorGUI.EndChangeCheck()) { // 执行一些额外的操作... } // 应用修改过的属性回到目标对象上 serializedObject.ApplyModifiedProperties(); } } ``` 这段代码展示了如何在一个自定义的 Inspector 中使用 `EditorGUILayout.PropertyField()` 方法来显示一个名为 `"myCustomField"` 的属性[^2]。 #### 处理复杂场景下的 Undo 功能支持 当涉及到复杂的嵌套结构时,比如动态加载其他组件或资源文件作为子项进行编辑的情况下,需要注意保持对撤销操作的支持。这可以通过调用 `Undo.RecordObject()` 来记录即将被修改的对象实例,在实际做出任何变更之前完成此步操作是非常重要的。 #### 提升用户体验的小技巧 除了基础的方法外,还可以探索更多高级特性的应用,例如结合 C# 属性增强功能,使代码更加简洁高效;或是采用模块化设计理念构建大型项目,从而简化维护工作量[^4]。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值