当前位置:网站首页>Unity Editor Extension Foundation, editorguilayout (III)
Unity Editor Extension Foundation, editorguilayout (III)
2022-06-28 12:21:00 【Unique_ eight hundred and forty-nine million nine hundred and n】
Summary :
1、 There are ways to draw a drop-down box DropdownButton、EnumMaskField、EnumPopup、IntPopup、Popup、EnumMaskPopup、MaskField,DropdownButton More trouble ,EnumMaskField、EnumMaskPopup、MaskField You can choose more than one .
2、 draw Slider It makes no difference , It's just MinMaxSlider Is the value range .
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
/// <summary>
/// Unity 5.6
/// </summary>
public class EditorGUILayoutOtherExample : EditorWindow
{
//PropertyField GetControlRect PrefixLabel
[MenuItem("EditorGUILayout/EditorGUILayoutOtherExample")]
static void Init()
{
EditorGUILayoutOtherExample window = (EditorGUILayoutOtherExample)EditorWindow.GetWindow(typeof(EditorGUILayoutOtherExample));
window.Show();
}
#region DropdownButton
private string m_itemString = "";
#endregion
#region EnumMaskField
public enum Example
{
Option_One = 1, //bits: 0000 0001
Option_Two = 2, //bits: 0000 0010
Option_Three = 4 //bits: 0000 0100
}
Example staticFlagMask = 0;
#endregion
#region EnumPopup
public enum OPTIONS
{
CUBE = 0,
SPHERE = 1,
PLANE = 2
}
public OPTIONS op;
#endregion
#region IntPopup
int selectedSize = 1;
string[] names = new string[] { "Normal", "Double", "Quadruple" };
int[] sizes = new int[]{1, 2, 4};
#endregion
#region Popup
public string[] options = new string[] { "Cube", "Sphere", "Plane" };
public int index = 0;
#endregion
#region EnumMaskPopup
public enum Options
{
CUBE = 0,
SPHERE = 1,
PLANE = 2
}
public Options m_options;
#endregion
#region InspectorTitlebar
bool fold = true;
bool fold2 = true;
Transform selectedTransform;
GameObject selectedGameObject;
#endregion
#region IntSlider
int m_intSlider = 1;
#endregion
#region IntSlider
float scale = 0.0f;
#endregion
#region MinMaxSlider
float minVal = -10;
float maxVal = 10;
float minLimit = -20;
float maxLimit = 20;
#endregion
#region PasswordField
string m_passwordField = "";
#endregion
void OnGUI()
{
#region DropdownButton
// More trouble
EditorGUILayout.BeginHorizontal();
EditorGUILayout.LabelField("DropdownButton:");
if (EditorGUILayout.DropdownButton(new GUIContent(m_itemString), FocusType.Keyboard))
{
var alls = new string[4] { "A", "B", "C", "D" };
GenericMenu _menu = new GenericMenu();
foreach (var item in alls)
{
if (string.IsNullOrEmpty(item))
{
continue;
}
// Add menu
_menu.AddItem(new GUIContent(item), m_itemString.Equals(item), OnValueSelected, item);
}
_menu.ShowAsContext();// Show menu
}
EditorGUILayout.EndHorizontal();
#endregion
#region EnumMaskField
// You can choose more than one
staticFlagMask = (Example)EditorGUILayout.EnumMaskField("EnumMaskField:", staticFlagMask);
#endregion
#region EnumPopup
op = (OPTIONS)EditorGUILayout.EnumPopup("EnumPopup:", op);
#endregion
#region IntPopup
selectedSize = EditorGUILayout.IntPopup("IntPopup: ", selectedSize, names, sizes);
#endregion
#region Popup
index = EditorGUILayout.Popup("Popup:",index, options);
#endregion
#region EnumMaskPopup
m_options = (Options)EditorGUILayout.EnumMaskPopup("EnumMaskPopup:", m_options);
#endregion
#region HelpBox
EditorGUILayout.HelpBox("HelpBox Error:", MessageType.Error);
EditorGUILayout.HelpBox("HelpBox Info:", MessageType.Info);
EditorGUILayout.HelpBox("HelpBox None:", MessageType.None);
EditorGUILayout.HelpBox("HelpBox Warning:", MessageType.Warning);
#endregion
#region InspectorTitlebar
selectedTransform = Selection.activeGameObject.transform;
selectedGameObject = Selection.activeGameObject;
fold = EditorGUILayout.InspectorTitlebar(fold, selectedTransform);
fold2 = EditorGUILayout.InspectorTitlebar(fold2, selectedGameObject);
#endregion
#region IntSlider
// Including the maximum and minimum values
m_intSlider = EditorGUILayout.IntSlider("IntSlider:",m_intSlider, 1, 10);
#endregion
#region MinMaxSlider
// Value range
EditorGUILayout.LabelField("Min Val:", minVal.ToString());
EditorGUILayout.LabelField("Max Val:", maxVal.ToString());
EditorGUILayout.MinMaxSlider("MinMaxSlider",ref minVal, ref maxVal, minLimit, maxLimit);
#endregion
EditorGUILayout.Space();
#region PasswordField
m_passwordField = EditorGUILayout.PasswordField("PasswordField:", m_passwordField);
EditorGUILayout.LabelField(" Text entered :", m_passwordField);
#endregion
#region SelectableLabel
// You can choose , Copy and paste
EditorGUILayout.SelectableLabel("SelectableLabel");
#endregion
scale = EditorGUILayout.Slider("Slider:",scale, 1, 100);
// Adaptive high , Can't adapt to wide
m_textArea = EditorGUILayout.TextArea(m_textArea);
m_vector2 = EditorGUILayout.Vector2Field("Vector2:", m_vector2);
m_vector3 = EditorGUILayout.Vector3Field("Vector3:", m_vector3);
m_vector4 = EditorGUILayout.Vector4Field("Vector4:", m_vector4);
}
string m_textArea = "";
Vector2 m_vector2;
Vector3 m_vector3;
Vector4 m_vector4;
#region DropdownButton
void OnValueSelected(object value)
{
m_itemString = value.ToString();
}
#endregion
}
Come here ,5.6 Version of EditorGUILayout All methods of class have been tried .
design sketch :

边栏推荐
猜你喜欢

【C语言】关于scanf()与scanf_s()的一些问题

Many benefits of SEO optimization are directly related to traffic

UGUI使用小技巧(五) Scroll Rect组件的使用

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

RemoteViews的作用及原理

Deep learning has a new pit! The University of Sydney proposed a new cross modal task, using text to guide image matting

Web3安全连载(3) | 深入揭秘NFT钓鱼流程及防范技巧

How to deploy the software testing environment?

Convert black mask picture to color annotation file

UGUI强制刷新Layout(布局)组件
随机推荐
JNI函数的2种书写方式
Sha256 encryption tool class
【C语言】二叉树的实现及三种遍历
Int~long long indicates the maximum and minimum number
真正的学懂三极管入门篇(经典)「建议收藏」
URL append parameter method, considering #$ Situation of
RemoteViews布局和类型限制源码分析
Deep learning has a new pit! The University of Sydney proposed a new cross modal task, using text to guide image matting
Graphics view framework for QT learning (to realize startup animation)
[C language] use of file read / write function
SHA256加密工具类
Redis 原理 - List
Chendanqi, Fang Fei, guquanquan and Li Bo won the prize, and the list of Sloan research award in 2022 was released
Leetcode 48. 旋转图像(可以,已解决)
Still using simpledateformat for time formatting? Be careful that the project collapses!
Self use demo of basic component integration of fluent
UGUI使用小技巧(六)Unity实现字符串竖行显示
. Net hybrid development solution 24 webview2's superior advantages over cefsharp
如何获取泛型的类型
Is tongdaxin stock software reliable? Is it safe to trade stocks on it?