当前位置:网站首页>【Unity编辑器扩展基础】、EditorGUILayout (一)
【Unity编辑器扩展基础】、EditorGUILayout (一)
2022-06-28 12:00:00 【Unique_849997563】
小结:
1、EditorGUILayout的各种Field和GUILayout的类似,但是EditorGUILayout可以复制粘贴;
2、因为OnGUI是每帧执行的,EditorGUILayout中类似TextField、IntSlider、ColorField需要传一个值,返回修改值的,需要将返回值赋值给临时变量;
3、params GUILayoutOption[] options可以传的参数在GUILayout类中可以找到: GUILayout.Width, GUILayout.Height, GUILayout.MinWidth, GUILayout.MaxWidth, GUILayout.MinHeight, GUILayout.MaxHeight, GUILayout.ExpandWidth, GUILayout.ExpandHeight
4、DelayedField延迟的输入框 在按下回车键或将焦点从文本字段移开之前,不会返回新值。
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
public class EditorGUILayoutFieldExample : EditorWindow
{
#region Field
//BoundsField
static Vector3 center = new Vector3(1, 2, 3);
static Vector3 size = new Vector3(1, 2, 3);
Bounds _bounds = new Bounds(center, size);
//ColorField
Color m_color = Color.white;
//CurveField
AnimationCurve m_curve = AnimationCurve.Linear(0, 0, 10, 10);
//DelayedDoubleField DelayedFloatField DelayedIntField DelayedTextField
double m_delayedDouble = 0;
float m_delayedFloat = 0;
int m_delayedInt = 0;
string m_delayedString = "";
//DoubleField FloatField IntField TextField
double m_fieldDouble = 0;
float m_fieldFloat = 0;
int m_fieldInt = 0;
string m_fieldString = "";
long m_fieldLong = 0;
//LayerField
int selectedLayer = 0;
//ObjectField
Object m_fieldObject;
//MaskField
int flags = 0;
string[] options = new string[] { "CanJump", "CanShoot", "CanSwim" };
//TagField
string tagStr = "Untagged";
//RectField
Rect m_rectFieldPos;
#endregion
[MenuItem("EditorGUILayout/EditorGUILayoutFieldExample")]
static void Init()
{
EditorGUILayoutFieldExample window = (EditorGUILayoutFieldExample)EditorWindow.GetWindow(typeof(EditorGUILayoutFieldExample));
window.Show();
}
void OnGUI()
{
#region Field 输入框
//BoundsField 边界输入框
_bounds = EditorGUILayout.BoundsField("BoundsField:",_bounds);
//ColorField 颜色输入框
m_color = EditorGUILayout.ColorField("ColorField:",m_color);
//CurveField 曲线输入框
m_curve = EditorGUILayout.CurveField("CurveField:", m_curve);
//DelayedField
m_delayedDouble = EditorGUILayout.DelayedDoubleField("DelayedDoubleField:", m_delayedDouble);
m_delayedFloat = EditorGUILayout.DelayedFloatField("DelayedFloatField:", m_delayedFloat);
m_delayedInt = EditorGUILayout.DelayedIntField("DelayedIntField:", m_delayedInt);
m_delayedString = EditorGUILayout.DelayedTextField("DelayedTextField:", m_delayedString);
m_fieldDouble = EditorGUILayout.DoubleField("DoubleField:", m_fieldDouble);
m_fieldFloat = EditorGUILayout.FloatField("FloatField:", m_fieldFloat);
m_fieldInt = EditorGUILayout.IntField("IntField:", m_fieldInt);
m_fieldString = EditorGUILayout.TextField("TextField:", m_fieldString);
m_fieldLong = EditorGUILayout.LongField("LongField:", m_fieldLong);
//LabelField
EditorGUILayout.LabelField("这是一个LabelField! ");
//LayerField 可以获取所有的Layer
selectedLayer = EditorGUILayout.LayerField("LayerField:", selectedLayer);
//ObjectField
m_fieldObject = EditorGUILayout.ObjectField(m_fieldObject, typeof(Object), true);
//MaskField
flags = EditorGUILayout.MaskField("MaskField:", flags, options);
//RectField
m_rectFieldPos = EditorGUILayout.RectField("RectField:", m_rectFieldPos);
//TagField
tagStr = EditorGUILayout.TagField("TagField:", tagStr);
#endregion
}
}
以上就是EditorGUILayout中各种Field的用法了。
效果图:

边栏推荐
- Simple understanding of ThreadLocal
- Prepare for Jin San Yin Si I. testers without experience in automated testing projects should look at it quickly
- 【C语言】判断三角形
- 【北京航空航天大学】考研初试复试资料分享
- 【vi/vim】基本使用及命令汇总
- AcWing 606. Average 1 (implemented in C language)
- Oracle date format exception: invalid number
- Open3d manual clipping point cloud
- KDD 2022 | 图“预训练、提示、微调”范式下的图神经网络泛化框架
- Share the easy-to-use fastadmin open source system - practical part
猜你喜欢

深度学习又有新坑了!悉尼大学提出全新跨模态任务,用文本指导图像进行抠图...

Array method in JS 2021.09.18

什么是数据合规?怎样做到数据合规?

Android应用安全之JNI混淆

Self use demo of basic component integration of fluent

Redis principle - List

RemoteViews布局和类型限制源码分析

Day30 JS notes BOM and DOM 2021.09.24

Simple understanding of ThreadLocal

In less than an hour, apple destroyed 15 startups
随机推荐
CDC synchronization if the primary key of a database table changes, will it be synchronized into two data or will it be synchronized to update the primary key?
Redis 原理 - List
AcWing 607. Average 2 (implemented in C language)
KDD 2022 | graph neural network generalization framework under the paradigm of "pre training, prompting and fine tuning"
How to get a generic type
SoapUI rookie tutorial
Practice and Thinking on the architecture of a set of 100000 TPS im integrated message system
Day28 strict mode, string JS 2021.09.22
Day23 JS notes 2021.09.14
If you want to change to software testing, how can you package your resume as a test engineer with 1 year of work experience
如何获取泛型的类型
【vi/vim】基本使用及命令汇总
fatal: unsafe repository (‘/home/anji/gopath/src/gateway‘ is owned by someone else)
In less than an hour, apple destroyed 15 startups
Redis principle - List
Packaging and publishing application of jetpack compose desktop version
开源项目维权成功案例: spug 开源运维平台成功维权
期货开户有门槛吗,如何网上安全的开通期货账户
The development and principle of the metacosmic system
What is DAPP system development and analytical understanding