当前位置:网站首页>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);
}
}
}
边栏推荐
猜你喜欢
图像处理8-CNN图像分类
Introduction to hexadecimal coding
jupyter远程服务器配置以及服务器开机自启
Un système de gestion de centre commercial pour la conception de cours de technologie d'application de base de données
Gradle's method of dynamically modifying APK package name
Kwai 20200412 recruitment
Haproxy+kept cluster setup 02
【云原生】微服务之Feign的介绍与使用
Redis的数据结构
Youyou1 of xlua knapsack system
随机推荐
[linear table] basic operation of bidirectional linked list specify node exchange
Sequence of map implementation classes
Wpf: solve the problem that materialdesign:dialoghost cannot be closed
Redis的数据结构
Minimap plug-in
Delete the last character of the string in golang
UE4 source code reading_ Bone model and animation system_ Animation compression
Use filechannel to copy files
Dotween plug-in
Installation of PHP FPM software +openresty cache construction
KunlunBase MeetUP 等您来!
十六进制编码简介
Flex flexible box layout
Graphics_ Games101/202 learning notes
Some understandings of 3dfiles
What does (+) in Oracle mean
UE4 source code reading_ Mobile synchronization
C language - Introduction - essence Edition - take you into programming (I)
Golang 时间格式整理
Vscode, idea, VIM development tool shortcut keys