当前位置:网站首页>Unity editor expansion - window, sub window, menu, right-click menu (context menu)
Unity editor expansion - window, sub window, menu, right-click menu (context menu)
2022-07-03 08:26:00 【T.D.C】
summary
- This paper studies the knowledge necessary to create editor windows
Post code
using UnityEditor;
using UnityEngine;
namespace DC.DCIMGUIBox
{
public class ChildWindowWindow : EditorWindow
{
[MenuItem("DC/IMGUI/ChildWindowWindow")]
public static void Open()
{
var window = GetWindow<ChildWindowWindow>();
window.minSize = new Vector2(400, 400);
}
Rect windowRect = new Rect(20, 20, 400, 50);
Rect windowRect2 = new Rect(320, 120, 120, 50);
void OnGUI()
{
BeginWindows();
windowRect = GUILayout.Window(0, windowRect, ChildWindow, "CW1");
windowRect2 = GUILayout.Window(1, windowRect2, ChildWindow, "CW2");
EndWindows();
}
void ChildWindow(int windowID)
{
GUI.DragWindow(new Rect(0, 0, windowRect.width, 16));
if (GUILayout.Button("Btn " + windowID))
{
Debug.Log(windowID);
}
}
}
}
Set window properties
// After creation, you can set the supported properties
var window = GetWindow<ChildWindowWindow>();
window.minSize = new Vector2(400, 400);
child window
- Just adjust one api Pass it on like a similar OnGUI Function to draw sub windows
- Incoming window id And size , Draw in the callback function ui that will do , Get the controls you need
- You can encapsulate child windows as objects as needed , This size can also be adjusted , Otherwise, if the sub window is too small, it may not display all
void OnGUI()
{
BeginWindows();
windowRect = GUILayout.Window(0, windowRect, ChildWindow, "CW1");
windowRect2 = GUILayout.Window(1, windowRect2, ChildWindow, "CW2");
EndWindows();
}
void ChildWindow(int windowID)
{
GUI.DragWindow(new Rect(0, 0, windowRect.width, 16));
if (GUILayout.Button("Btn " + windowID))
{
Debug.Log(windowID);
}
}
menu
// So you can do it unity Create a path for the menu bar of DC/IMGUI/ChildWindowWindow Here's the menu
[MenuItem("DC/IMGUI/ChildWindowWindow")]
public static void Open()
{
var window = GetWindow<ChildWindowWindow>();
window.minSize = new Vector2(400, 400);
}
Right-click menu ( Context menu )
- The right-click context menu is unity Subset of the right-click menu , It is shown that unity Right click menu or a group of menus in the right-click menu
- How to add items to the right-click menu
// Similar to the menu , But with Assets start
[MenuItem("Assets/DC/xxx")]
- Listen for right click events
Event evt = Event.current;
if (evt.type == EventType.ContextClick){
...
}
- Show the right-click menu
// Key messages 2 individual , Location , Menu path
EditorUtility.DisplayPopupMenu(new Rect(mousePos.x, mousePos.y, 0, 0), "Assets/DC", null);
- Complete code
using UnityEditor;
using UnityEngine;
namespace DC.DCIMGUIBox
{
public class PopMenuWindow_01 : EditorWindow
{
[MenuItem("DC/IMGUI/PopMenuWindow_01")]
public static void Open()
{
var window = GetWindow<PopMenuWindow_01>();
window.minSize = new Vector2(800, 600);
}
int index = 0;
string[] options = { "Rigidbody", "Box Collider", "Sphere Collider" };
void OnGUI()
{
Event evt = Event.current;
Rect contextRect = new Rect(10, 10, 100, 100);
EditorGUI.DrawRect(contextRect, Color.blue);
if (evt.type == EventType.ContextClick)
{
Vector2 mousePos = evt.mousePosition;
if (contextRect.Contains(mousePos))
{
EditorUtility.DisplayPopupMenu(new Rect(mousePos.x, mousePos.y, 0, 0), "Assets/DC", null);
}
}
var areaRect = new Rect(0, 200, 200, 40);
EditorGUI.DrawRect(areaRect, Color.blue);
index = EditorGUI.Popup(areaRect, "Component:", index, options);
}
}
}
边栏推荐
- Unity learning notes
- Detailed explanation of all transfer function (activation function) formulas of MATLAB neural network
- 数据的存储
- Vscode, idea, VIM development tool shortcut keys
- Transmit pictures with Base64 encoding
- Explain sizeof, strlen, pointer, array and other combination questions in detail
- Classes and objects
- 796 · unlock
- 100 GIS practical application cases (78) - Multi compliance database design and data warehousing
- Cloudcompare learning (1) - cloudcompare compilation and common plug-in implementation
猜你喜欢

Solution détaillée de toutes les formules de fonction de transfert (fonction d'activation) du réseau neuronal MATLAB

【更新中】微信小程序学习笔记_3

About the problem that the editor and the white screen of the login interface cannot be found after the location of unityhub is changed

Constraintlayout's constraintset dynamically modifies constraints

Un système de gestion de centre commercial pour la conception de cours de technologie d'application de base de données
![[updating] wechat applet learning notes_ three](/img/05/958b8d62d3a42b38ca1a2d8631a7f8.png)
[updating] wechat applet learning notes_ three

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

数据分析练习题

Minimap plug-in

the installer has encountered an unexpected error installing this package
随机推荐
Three characteristics
Luaframwrok handles resource updates
Golang 字符串分割,替换和截取
the installer has encountered an unexpected error installing this package
Cesium for unreal quick start - simple scenario configuration
Get to know unity2 for the first time
redis集群系列四
简易入手《SOM神经网络》的本质与原理
Simple demo of solving BP neural network by gradient descent method
[linear table] basic operation of bidirectional linked list specify node exchange
Xlua task list youyou
Some understandings of 3dfiles
Transfinite hacker cognition
Puhua PLM empowers the whole scene product lifecycle management and helps the enterprise digital transformation of the main line of products
ArrayList
了解小程序的笔记 2022/7/3
What is BFC?
UE4 source code reading_ Bone model and animation system_ Animation node
Gradle's method of dynamically modifying APK package name
数据分析练习题