当前位置:网站首页>Unity editor expansion - controls, layouts
Unity editor expansion - controls, layouts
2022-07-03 08:26:00 【T.D.C】
Control 、 Layout
- Custom control's 2 In the form of
- Combine existing controls to handle more complex logic and return more complex data
- Handle the incident by yourself , Draw a unique interface
- The horizontal layout , Let the control automatically typeset from left to right
- Vertical layout , Let the control automatically typeset from top to bottom
Running results

Code
using UnityEditor;
using UnityEngine;
namespace DC.DCIMGUIBox
{
public class ControlsAndLayoutWindow : EditorWindow
{
[MenuItem("DC/IMGUI/ControlsAndLayoutWindow")]
public static void Open()
{
var window = GetWindow<ControlsAndLayoutWindow>();
window.minSize = new Vector2(800, 600);
}
private int toolbar;
private bool area1Blue = true;
private bool area2Red = true;
public Vector2 btnListScrollPos;
private Gradient gradient = new Gradient();
public void OnGUI()
{
// Start horizontal layout
GUILayout.BeginHorizontal(GUILayout.ExpandWidth(true));
// gradient
gradient = EditorGUILayout.GradientField(gradient, GUILayout.Width(100));
// Tool switch
toolbar = GUILayout.Toolbar(toolbar, new[] {"Area1", "Area2"});
GUILayout.EndHorizontal();
// No line wrapping
GUILayout.BeginHorizontal("many button h", GUILayout.MaxHeight(20));
for (int i = 0; i < 20; i++)
{
if (GUILayout.Button(i.ToString(), GUILayout.Width(60 + i)))
{
Debug.Log("button " + i);
}
}
GUILayout.EndHorizontal();
// Set the maximum 400 The width will still exceed , Don't wrap
GUILayout.BeginHorizontal("many button h", GUILayout.MaxWidth(400), GUILayout.MaxHeight(40));
for (int i = 0; i < 20; i++)
{
if (GUILayout.Button(i.ToString(), GUILayout.Width(60 + i)))
{
Debug.Log("button " + i);
}
}
GUILayout.EndHorizontal();
if (toolbar == 0)
{
// Set an area , Start from this area UI
// After this method is executed, the coordinates of the mouse will have a relative transformation , If you listen to mouse events , The mouse position becomes relative to the specified starting point
GUILayout.BeginArea(new Rect(0, 100, 200, 200));
area1Blue = ColoredRectToggle(new Rect(0, 0, 100, 100), area1Blue, "blue", Color.blue, Color.red);
if (Event.current.type == EventType.MouseDown)
{
Debug.Log("box a" + Event.current.mousePosition);
}
GUILayout.EndArea();
}
else
{
GUILayout.BeginArea(new Rect(210, 100, 200, 200));
area2Red = ColoredRectToggle(new Rect(0, 0, 100, 100), area2Red, "red", Color.red, Color.blue);
if (Event.current.type == EventType.MouseDown)
{
Debug.Log("box b" + Event.current.mousePosition);
}
GUILayout.EndArea();
}
GUI.Box(new Rect(0, 300, 100, 100), "hello box 1");
GUILayout.BeginArea(new Rect(110, 300, 100, 100));
GUILayout.Box("hello box2", GUILayout.Height(100));
GUILayout.EndArea();
// Button list
var btnListRect = new Rect(400, 100, 200, 200);
GUILayout.BeginArea(btnListRect);
EditorGUI.DrawRect(new Rect(0, 0, btnListRect.width, btnListRect.height), new Color(.5f, 1.0f, 1.0f, 1));
btnListScrollPos =
GUILayout.BeginScrollView(btnListScrollPos, false, true, GUILayout.Height(btnListRect.height));
GUILayout.BeginVertical("many button");
for (int i = 0; i < 10; i++)
{
if (GUILayout.Button(i.ToString(), GUILayout.Height(20 + i)))
{
Debug.Log("button " + i);
}
}
GUILayout.EndVertical();
GUILayout.EndScrollView();
GUILayout.EndArea();
}
/// <summary>
/// Customize a control
/// </summary>
/// <param name="layout"></param>
/// <param name="isCheck"></param>
/// <param name="controlName"></param>
/// <param name="a"></param>
/// <param name="b"></param>
/// <returns></returns>
public bool ColoredRectToggle(Rect layout, bool isCheck, string controlName, Color a, Color b)
{
EditorGUI.DrawRect(layout, isCheck ? a : b);
return GUILayout.Toggle(area2Red, controlName);
}
}
}
边栏推荐
- UE4 plug in development
- Go resolve ID card
- [usaco12mar]cows in a skyscraper g (state compression DP)
- E: Unable to locate package ROS melody desktop full
- Graphics_ Games101/202 learning notes
- Golang的range
- Simply start with the essence and principle of SOM neural network
- [public key cryptography] ECC elliptic cryptosystem (implementing ElGamal encryption method)
- UE4 source code reading_ Bone model and animation system_ Animation process
- MXone Pro自适应2.0影视模板西瓜视频主题苹果cmsV10模板
猜你喜欢

Introduction to hexadecimal coding

UE4 source code reading_ Bone model and animation system_ Animation compression

Vscode, idea, VIM development tool shortcut keys
![[set theory] order relation (the relation between elements of partial order set | comparable | strictly less than | covering | Haas diagram)](/img/df/a034032e203e7935dafaf8a71cb6c8.jpg)
[set theory] order relation (the relation between elements of partial order set | comparable | strictly less than | covering | Haas diagram)

the installer has encountered an unexpected error installing this package

matlab神經網絡所有傳遞函數(激活函數)公式詳解

详解sizeof、strlen、指针和数组等组合题
![P1596 [USACO10OCT]Lake Counting S](/img/a7/07a84c93ee476788d9443c0add808b.png)
P1596 [USACO10OCT]Lake Counting S

基于SSM的校园失物招领平台,源码,数据库脚本,项目导入运行视频教程,论文撰写教程

Chocolate installation
随机推荐
Golang的range
jupyter远程服务器配置以及服务器开机自启
About Wireshark's unsuccessful installation of npcap
Haproxy+kept cluster setup 02
Intersectionpicker in osgearth
Advanced OSG collision detection
Base64编码简介
Easy touch plug-in
Transfinite hacker cognition
【音视频】ijkplayer错误码
Golang 时间格式整理
MAE
Chain length value
Base64和Base64URL
Golang 字符串分割,替换和截取
796 · 开锁
the installer has encountered an unexpected error installing this package
Flex flexible box layout
Osgearth topographic shading map drawing
the installer has encountered an unexpected error installing this package