小結(jié):
1钠四、EditorGUILayout的各種Field和GUILayout的類似盗扒,但是EditorGUILayout可以復(fù)制粘貼;
2缀去、因為OnGUI是每幀執(zhí)行的侣灶,EditorGUILayout中類似TextField、IntSlider缕碎、ColorField需要傳一個值褥影,返回修改值的,需要將返回值賦值給臨時變量阎曹;
3伪阶、params GUILayoutOption[] options可以傳的參數(shù)在GUILayout類中可以找到: GUILayout.Width, GUILayout.Height, GUILayout.MinWidth, GUILayout.MaxWidth, GUILayout.MinHeight, GUILayout.MaxHeight, GUILayout.ExpandWidth, GUILayout.ExpandHeight
4、DelayedField延遲的輸入框 在按下回車鍵或?qū)⒔裹c從文本字段移開之前处嫌,不會返回新值栅贴。
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的用法了熏迹。
效果圖:
?