当前位置:网站首页>【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的用法了。
效果图:
边栏推荐
- 2. single digit statistics
- 来吧元宇宙,果然这热度一时半会儿过不去了
- RemoteViews的作用及原理
- KDD 2022 | graph neural network generalization framework under the paradigm of "pre training, prompting and fine tuning"
- 期货开户有门槛吗,如何网上安全的开通期货账户
- AcWing 608. Poor (implemented in C language)
- Usage and principle of precomputedtextcompat
- Build your own website (18)
- How to deploy the software testing environment?
- SHA256加密工具类
猜你喜欢
Leetcode 705. 设计哈希集合
【vi/vim】基本使用及命令汇总
深度学习又有新坑了!悉尼大学提出全新跨模态任务,用文本指导图像进行抠图...
.NET混合开发解决方案24 WebView2对比CefSharp的超强优势
JS foundation 8
Day36 JS notes ecma6 syntax 2021.10.09
Function and principle of remoteviews
What method is required for word, PDF and txt files to realize full-text content retrieval?
Using soapUI to obtain freemaker's FTL file template
水果FL Studio/Cubase/Studio one音乐宿主软件对比
随机推荐
JS foundation 10
Redis hash hash type string (5)
AGCO AI frontier promotion (2.16)
Chapter 2 do you remember the point, line and surface (2)
Software test interview classic + 1000 high-frequency real questions, and the hit rate of big companies is 80%
【C语言】随机数文件对其进行三种排序方法
Day33 JS note event (Part 2) September 28, 2021
Two writing methods of JNI function
NFT card chain game system development DAPP construction technical details
AcWing 604. Area of circle (implemented in C language)
3. seat number
Bisection (integer bisection and floating point bisection)
What is data compliance? How to achieve data compliance?
IO stream of file and Base64
Cannot redeclare block range variables
2. single digit statistics
Web3安全连载(3) | 深入揭秘NFT钓鱼流程及防范技巧
Source code analysis of ArrayList
AcWing 605. Simple product (implemented in C language)
MapReduce project case 1