当前位置:网站首页>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);
}
}
}
边栏推荐
- [usaco12mar]cows in a skyscraper g (state compression DP)
- 梯度下降法求解BP神经网络的简单Demo
- [K & R] Chinese Second Edition personal questions Chapter1
- UE4 source code reading_ Bone model and animation system_ Animation compression
- Golang的range
- Base64 and base64url
- Simply start with the essence and principle of SOM neural network
- 详解sizeof、strlen、指针和数组等组合题
- swagger文档配置
- E: Unable to locate package ROS melody desktop full
猜你喜欢

Redis data structure
![[set theory] order relation (hastu example | divisive relation hastu | inclusive relation hastu | refinement relation hastu)](/img/de/1c75b5e7ed79aca47462de365428a7.jpg)
[set theory] order relation (hastu example | divisive relation hastu | inclusive relation hastu | refinement relation hastu)

matlab神经网络所有传递函数(激活函数)公式详解

UE4 source code reading_ Bone model and animation system_ Animation process

Chocolate installation

数据分析练习题

Haproxy+kept cluster setup 02

Youyou1 of xlua knapsack system

L'installateur a été installé avec une erreur inattendue

Wpf: solve the problem that materialdesign:dialoghost cannot be closed
随机推荐
UE4 plug in development
LinkList
Unity4.3.1 engine source code compilation process
[public key cryptography] ECC elliptic cryptosystem (implementing ElGamal encryption method)
Three characteristics
梯度下降法求解BP神经网络的简单Demo
ArrayList
Yolo series --- xml2txt script
Minimap plug-in
MAE
Huawei interview summary during the epidemic
Chocolate installation
Osgearth north arrow display
UE4 source code reading_ Bone model and animation system_ Animation process
C language - Introduction - essence Edition - take you into programming (I)
【更新中】微信小程序学习笔记_3
P1896 [scoi2005] non aggression (shape pressure DP)
Creation of osgearth earth files to the earth ------ osgearth rendering engine series (1)
the installer has encountered an unexpected error installing this package
Golang 字符串分割,替换和截取