当前位置:网站首页>Unity Editor Extension Foundation, guilayout
Unity Editor Extension Foundation, guilayout
2022-06-28 12:21:00 【Unique_ eight hundred and forty-nine million nine hundred and n】
Summary :
1、TextArea、TextField The text input box cannot be copied ,TextArea You can change lines , Adaptive width .
2、 Parameters can be transferred to GUIContent Can display pictures or text .
3、 GUILayout.Window Need to call BeginWindows、 EndWindows To display the window .
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
/// <summary>
/// Unity 5.6
/// GUILayoutOption Parameters :
/// GUILayout.Width, GUILayout.Height, GUILayout.MinWidth, GUILayout.MaxWidth, GUILayout.MinHeight, GUILayout.MaxHeight, GUILayout.ExpandWidth, GUILayout.ExpandHeight
/// </summary>
public class GUILayoutControlExample : EditorWindow
{
[MenuItem("Examples/GUILayoutControlExample")]
static void Init()
{
GUILayoutControlExample window = (GUILayoutControlExample)EditorWindow.GetWindow(typeof(GUILayoutControlExample));
window.Show();
}
void OnEnable()
{
#region Box
m_boxTexture = Resources.Load("Textures/EquipIcon/12001") as Texture;
m_boxLable = "GUILayout Of Box Control ! After changing the window size, the text can be adaptive ";
#endregion
}
// Box
Texture m_boxTexture;
string m_boxLable ;
//Label
string m_lableText = "GUILayout Of Label Control ! Text cannot be adaptive after changing the window size ";
//PasswordField
string m_passwordFieldText = "";
// SelectionGrid
int selGridInt = 0;
string[] selStrings = new string[] { "radio1", "radio2", "radio3", "radio4" };
int selectIndex = -1;
//BeginScrollView
public Vector2 scrollPosition;
public string longString = "This is a long-ish string";
//BeginArea
Rect area = new Rect(500, 20, 200, 200);
//GUILayout.Window
Rect windowRect = new Rect(200, 50, 200, 50);
//Scrollbar
public float vSbarValue;
public float hSbarValue;
//Slider
public float vSliderValue;
public float hSliderValue;
//TextArea
string m_textAtea = "TextArea The text box ";
//TextField
string m_textField = "TextField Input box ";
//Toggle
bool m_toggle = true;
//ToolBar
int toolbarInt = 0;
int toolbarIndex = -1;
string[] toolbarStrings = new string[] { "Toolbar1", "Toolbar2", "Toolbar3" };
void OnGUI()
{
// Parameters can be transferred to GUIContent Can display pictures or text
#region Box
// The size of the displayed image is the size of the resource , Text can be adaptive
if (m_boxTexture != null)
{
GUILayout.Box(m_boxTexture);
//GUILayout.Box(new GUIContent(m_boxLable, m_boxTexture));
}
GUILayout.Box(m_boxLable);
#endregion
#region Button Auto layout button
//Button: Pressing and lifting the mouse is an effective click , Press and lift to return True.
//RepeatButton: When the mouse is pressed, it will always return True.( If not called Repaint function , Press down 、 Lift up and return True)
if (GUILayout.Button("Button"))
{
Debug.Log(" Click button ");
Repaint();
}
if (GUILayout.RepeatButton("RepeatButton"))
{
Debug.Log(" Click on RepeatButton Button ");
Repaint();
}
#endregion
//FlexibleSpace Adaptive spacing
GUILayout.FlexibleSpace();
GUILayout.Label("Lable:"+ m_lableText);
//PasswordField Incoming string You need to initialize a default value first , Otherwise, an empty exception will be reported
m_passwordFieldText = GUILayout.PasswordField(m_passwordFieldText, '*');
GUI.color = Color.red;
GUILayout.Label("PasswordField:" + m_passwordFieldText);
GUI.color = Color.white;
#region SelectionGrid
// It feels like UGUI Of GridLayoutGroup equally
selGridInt = GUILayout.SelectionGrid(selGridInt, selStrings, 2);
if (selectIndex!= selGridInt)
{
Debug.Log(" I chose : " + selStrings[selGridInt]);
selectIndex = selGridInt;
}
#endregion
GUILayout.Space(20);
// Adaptive width , You can change lines
m_textAtea = GUILayout.TextArea(m_textAtea);
// It's not adaptive , There is only one line
m_textField = GUILayout.TextField(m_textField);
m_toggle = GUILayout.Toggle(m_toggle, "Toggle:");
toolbarInt = GUILayout.Toolbar(toolbarInt, toolbarStrings);
if (toolbarIndex!=toolbarInt)
{
Debug.Log(" Click. :" + toolbarStrings[toolbarInt]);
toolbarIndex = toolbarInt;
}
// Scroll bar
vSbarValue = GUILayout.VerticalScrollbar(vSbarValue, 1.0F, 10.0F, 0.0F);
hSbarValue = GUILayout.HorizontalScrollbar(hSbarValue, 1.0F, 0.0F, 10.0F);
// Slider bar
vSliderValue = GUILayout.VerticalSlider(vSliderValue, 10.0F, 0.0F);
hSliderValue = GUILayout.HorizontalSlider(hSliderValue, 0.0F, 10.0F);
// Create a GUI Region , Controls within a region are only affected by the region
GUILayout.BeginArea(area);
GUILayout.BeginHorizontal();
#region Vertical A
GUILayout.BeginVertical();
GUILayout.Box("Text1");
// There is a gap between controls
GUILayout.Space(20f);
GUILayout.Box("Text1");
GUILayout.Space(20f);
GUILayout.Button("Button");
GUILayout.EndVertical();
#endregion
#region Vertical B
GUILayout.BeginVertical();
GUILayout.Box("Text3");
// Automatically measure the gap distance
GUILayout.FlexibleSpace();
GUILayout.Box("Text4");
GUILayout.FlexibleSpace();
GUILayout.Button("Button");
GUILayout.EndVertical();
#endregion
GUILayout.EndHorizontal();
GUILayout.EndArea();
//
scrollPosition = GUILayout.BeginScrollView(scrollPosition, GUILayout.Width(300), GUILayout.Height(100));
GUILayout.Label(longString);
if (GUILayout.Button("Clear"))
longString = "";
//
GUILayout.EndScrollView();
if (GUILayout.Button("Add More Text"))
longString += "\nHere is another line";
//
BeginWindows();
windowRect = GUILayout.Window(0, windowRect, DoMyWindow, "GUILayout Of Window");
EndWindows();
}
void DoMyWindow(int windowID)
{
if (GUILayout.Button("Button"))
Debug.Log(" Click button !");
GUI.DragWindow();
}
}
边栏推荐
猜你喜欢

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

Android应用安全之JNI混淆

Data analysis learning notes
![[C language] use of nested secondary pointer of structure](/img/59/8b61805431e152995c250f6dd08e29.png)
[C language] use of nested secondary pointer of structure

SEO优化的许多好处是与流量有直接关系

KDD 2022 | 图“预训练、提示、微调”范式下的图神经网络泛化框架

Software test interview classic + 1000 high-frequency real questions, and the hit rate of big companies is 80%

【vi/vim】基本使用及命令汇总

ByteV搭建动态数字孪生网络安全平台----助力网络安全发展

RemoteViews的作用及原理
随机推荐
In less than an hour, apple destroyed 15 startups
Vivo手机的权限管理
Map排序工具类
What are the common modes of financial products in 2022?
【经验分享】Django开发中常用到的数据库操作总结
6.A-B
Convert black mask picture to color annotation file
Chendanqi, Fang Fei, guquanquan and Li Bo won the prize, and the list of Sloan research award in 2022 was released
Given two points and a point with a middle scale, find the coordinates of the point
Redis hash hash type string (5)
PyQt5可视化开发
Remoteviews layout and type restriction source code analysis
MapReduce项目案例1
【Unity编辑器扩展实践】、利用txt模板动态生成UI代码
Using MySQL database in the express framework of node
[vi/vim] basic usage and command summary
【C语言】NextDay问题
AGCO AI frontier promotion (2.16)
AcWing 608. Poor (implemented in C language)
5. Sum of N numbers