当前位置:网站首页>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 :

边栏推荐
猜你喜欢

Prepare for Jin San Yin Si I. testers without experience in automated testing projects should look at it quickly

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

ArrayList源码解析

.NET混合开发解决方案24 WebView2对比CefSharp的超强优势

. Net hybrid development solution 24 webview2's superior advantages over cefsharp

Is it feasible to be a programmer at the age of 26?

Necessary for beginners PR 2021 quick start tutorial, PR green screen matting operation method

EMC RS485接口EMC电路设计方案
Three ways to implement LRU cache (recommended Collection)

How to deploy the software testing environment?
随机推荐
In less than an hour, apple destroyed 15 startups
fatal: unsafe repository (‘/home/anji/gopath/src/gateway‘ is owned by someone else)
AcWing 604. Area of circle (implemented in C language)
RemoteViews的作用及原理
自定义标题栏View
2022年理财产品的常见模式有哪些?
Share the easy-to-use fastadmin open source system - practical part
Source code analysis of ArrayList
PrecomputedTextCompat用法及原理
Bisection (integer bisection and floating point bisection)
Why do many people want to change careers as programmers, while some programmers want to change careers as others?
AcWing 605. Simple product (implemented in C language)
Two writing methods of JNI function
【C语言】如何很好的实现复数类型
MapReduce项目案例3——温度统计
SHA256加密工具类
ArrayList源码解析
Remoteviews layout and type restriction source code analysis
Is tongdaxin stock software reliable? Is it safe to trade stocks on it?
EMC RS485接口EMC电路设计方案