当前位置:网站首页>Unity Editor Extension Foundation, editorguilayout (II)
Unity Editor Extension Foundation, editorguilayout (II)
2022-06-28 12:21:00 【Unique_ eight hundred and forty-nine million nine hundred and n】
Summary :
1、 similar BeginFadeGroup、BeginHorizontal All layout functions have corresponding EndFadeGroup、EndHorizontal, They are one-to-one correspondence ;
2、 establish ToggleGroup, After closing this ToggleGroup None of the contents under this group can be modified under this group .
3、BeginScrollView The return value is the position of the sliding area , You need to save it , To change BeginScrollView The location of .
using UnityEngine;
using UnityEditor;
using UnityEditor.AnimatedValues;
/// <summary>
/// Unity 5.6
/// </summary>
public class EditorGUILayoutExample : EditorWindow
{
#region BeginFadeGroup
AnimBool m_ShowExtraFields;
string m_String;
Color m_Color = Color.white;
int m_Number = 0;
#endregion
#region BeginScrollView
Vector2 scrollPos;
string m_content = "";
string t = " this yes One individual measuring try Scroll view Of writing Ben !\n";
#endregion
#region BeginToggleGroup
bool[] pos = new bool[3] { true, true, true };
bool posGroupEnabled = true;
#endregion
#region Foldout
bool showFoldout = true;
#endregion
[MenuItem("EditorGUILayout/EditorGUILayoutExample")]
static void Init()
{
EditorGUILayoutExample window = (EditorGUILayoutExample)EditorWindow.GetWindow(typeof(EditorGUILayoutExample));
window.Show();
}
void OnEnable()
{
#region BeginFadeGroup
m_ShowExtraFields = new AnimBool(true);// Create a AnimBool object ,true Is the default display .
m_ShowExtraFields.valueChanged.AddListener(Repaint);// Monitor redrawing
#endregion
}
void OnGUI()
{
#region BeginFadeGroup
m_ShowExtraFields.target = EditorGUILayout.ToggleLeft(" Show collapsed content ", m_ShowExtraFields.target);// Select the switch with the box on the left
m_ShowExtraFields.target = EditorGUILayout.Toggle(" Show collapsed content ", m_ShowExtraFields.target);// Select the switch with the box on the right
// Create a collapsed block with fade animation Return value bool, Parameters float
if (EditorGUILayout.BeginFadeGroup(m_ShowExtraFields.faded))
{
EditorGUI.indentLevel++;// Indent depth increases , Following GUI Will increase indent
EditorGUILayout.LabelField("ColorColorColorColorColorColorColorColorColorColor");// TAB bar
EditorGUILayout.PrefixLabel("ColorColorColorColorColorColorColorColorColorColor");// Prefix label
m_Color = EditorGUILayout.ColorField(m_Color);
EditorGUILayout.PrefixLabel("Text");
m_String = EditorGUILayout.TextField(m_String);// The text box
EditorGUILayout.PrefixLabel("Number");
m_Number = EditorGUILayout.IntSlider(m_Number, 0, 10);//Int Slider bar
EditorGUI.indentLevel--;// The indent depth decreases , Following GUI Will reduce indent
}
EditorGUILayout.EndFadeGroup();
#endregion
#region Foldout
showFoldout = EditorGUILayout.Foldout(showFoldout, " Fold sub objects :");
if (showFoldout)
{
EditorGUI.indentLevel++;
EditorGUILayout.LabelField(" Collapse block content 1");
EditorGUI.indentLevel++;
EditorGUILayout.LabelField(" Collapse block content 2");
EditorGUI.indentLevel--;
EditorGUI.indentLevel--;
EditorGUILayout.LabelField(" Collapse block content 3");
}
#endregion
#region BeginHorizontal Horizontal layout
Rect r = EditorGUILayout.BeginHorizontal("Button");
if (GUI.Button(r, GUIContent.none))
Debug.Log("Go here");
GUILayout.Label("I'm inside the button");
GUILayout.Label("So am I");
EditorGUILayout.EndHorizontal();
EditorGUILayout.BeginHorizontal();
GUILayout.Label(" The first content ");
GUILayout.Label(" Second content ");
if (GUILayout.Button(" The third button "))
{
Debug.Log("GUILayout The button ");
}
EditorGUILayout.EndHorizontal();
#endregion
#region BeginVertical Vertical layout
EditorGUILayout.BeginVertical();
GUILayout.Label(" The first content ");
GUILayout.Label(" Second content ");
if (GUILayout.Button(" The third button "))
{
Debug.Log("GUILayout The button ");
}
EditorGUILayout.EndVertical();
#endregion
#region BeginScrollView
// You need to assign the return value to a temporary variable , Otherwise, it won't move
// You can add GUILayoutOption Parameter control size
scrollPos = EditorGUILayout.BeginScrollView(scrollPos, GUILayout.Width(200), GUILayout.Height(100));
GUILayout.Label(m_content);
EditorGUILayout.EndScrollView();
EditorGUILayout.BeginHorizontal();
if (GUILayout.Button(" Add content "))
m_content += t;
if (GUILayout.Button(" Empty content "))
m_content = "";
EditorGUILayout.EndHorizontal();
#endregion
#region BeginToggleGroup
posGroupEnabled = EditorGUILayout.BeginToggleGroup("ToggleGroup", posGroupEnabled);
EditorGUILayout.BeginVertical();
pos[0] = EditorGUILayout.Toggle("Toggle1", pos[0]);
pos[1] = EditorGUILayout.Toggle("Toggle2", pos[1]);
pos[2] = EditorGUILayout.Toggle("Toggle3", pos[2]);
if (GUILayout.Button(" Add content "))
m_content += t;
m_String = EditorGUILayout.TextField(m_String);
EditorGUILayout.EndVertical();
EditorGUILayout.EndToggleGroup();
#endregion
// Draw a center dividing line
EditorGUILayout.BeginHorizontal();
GUILayout.FlexibleSpace();
GUILayout.Label("----------------- Split line -----------------");
GUILayout.FlexibleSpace();
EditorGUILayout.EndHorizontal();
}
}
That's all EditorGUILayout The usage of various layout functions in .
design sketch :

边栏推荐
- 【JS】斐波那契数列实现(递归与循环)
- 【编解码】从零开始写H264解码器(1) 总纲
- Web3安全连载(3) | 深入揭秘NFT钓鱼流程及防范技巧
- [Beijing University of Aeronautics and Astronautics] information sharing for the first and second examinations of postgraduate entrance examination
- Is there a threshold for opening futures accounts? How to open futures accounts safely on the Internet
- [C language] use of file read / write function
- 【Unity编辑器扩展实践】、利用txt模板动态生成UI代码
- pwn入门(1)二进制基础
- 30套JSP网站源代码合集「建议收藏」
- Map sorting tool class
猜你喜欢

Necessary for beginners PR 2021 quick start tutorial, PR green screen matting operation method
![[C language] use of nested secondary pointer of structure](/img/59/8b61805431e152995c250f6dd08e29.png)
[C language] use of nested secondary pointer of structure

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

2018 joint examination of nine provinces & Merging of line segment trees

智联招聘基于 Nebula Graph 的推荐实践分享

Remoteviews layout and type restriction source code analysis

UGUI强制刷新Layout(布局)组件

【C语言】二叉树的实现及三种遍历

What is data compliance? How to achieve data compliance?

【vi/vim】基本使用及命令汇总
随机推荐
30套JSP网站源代码合集「建议收藏」
Is it feasible to be a programmer at the age of 26?
女子高考落榜读专科逆袭买千万别墅,考得不好真的没关系
Redis principle - List
【编解码】从零开始写H264解码器(1) 总纲
Is tongdaxin stock software reliable? Is it safe to trade stocks on it?
Many benefits of SEO optimization are directly related to traffic
What are the common modes of financial products in 2022?
已知两个点和中间一个比例的点,求该点坐标
Setting overridesorting for canvas does not take effect
Difference (one dimension)
[C language] three sorting methods for random number files
【Unity编辑器扩展基础】、GUI
Bisection (integer bisection and floating point bisection)
PyQt5可视化开发
Still using simpledateformat for time formatting? Be careful that the project collapses!
Android应用安全之JNI混淆
深度学习又有新坑了!悉尼大学提出全新跨模态任务,用文本指导图像进行抠图...
3. seat number
AGCO AI frontier promotion (2.16)