当前位置:网站首页>Unity Editor Extension - drag and drop
Unity Editor Extension - drag and drop
2022-07-03 08:27:00 【T.D.C】
Drag and drop
- 2 Methods
- Use ChildWindow
- Custom control processing mouse drag event processing completes the change of control position
design sketch
- Click on add Create subwindow
- After selecting the window, link the currently selected window with the previously selected window with a line

This paper introduces the use of ChildWindow The drag and drop
using System;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
namespace DC.DCIMGUIBox
{
public class WindowNodeData
{
public Rect rect;
public bool selected;
}
public class DragWindow : EditorWindow
{
[MenuItem("DC/IMGUI/DragWindow")]
public static void Open()
{
var window = GetWindow<DragWindow>();
window.minSize = new Vector2(800, 600);
}
public List<WindowNodeData> nodeDataList = new List<WindowNodeData>();
List<Tuple<WindowNodeData, WindowNodeData>> lines = new List<Tuple<WindowNodeData, WindowNodeData>>();
private WindowNodeData lastSelectedWindow = null;
public void OnGUI()
{
GUILayout.BeginHorizontal();
if (GUILayout.Button("add"))
{
nodeDataList.Add(new WindowNodeData() {rect = new Rect(100, 100, 200, 100)});
}
GUILayout.EndHorizontal();
var col = new Color(0.8f, 0.3f, 0.3f);
for (int i = 0; i < lines.Count; i++)
{
var line = lines[i];
var startPos = line.Item1.rect.center;
var endPos = line.Item2.rect.center;
DrawConnectLine(new Vector3(startPos.x, startPos.y), new Vector3(endPos.x, endPos.y), col);
}
BeginWindows();
for (int i = 0; i < nodeDataList.Count; i++)
{
nodeDataList[i].rect = GUILayout.Window(i, nodeDataList[i].rect, WindowNode, i.ToString());
}
EndWindows();
}
public static void DrawConnectLine(Vector3 startPos, Vector3 endPos, Color color)
{
var startTangent = new Vector3(startPos.x + Mathf.Sign(endPos.x - startPos.x) * 10, startPos.y, startPos.z);
var endTangent = new Vector3(endPos.x + Mathf.Sign(endPos.y - startPos.y) * 10, endPos.y, endPos.z);
Handles.DrawBezier(startPos, endPos, startTangent, endTangent, color, CustomControls.texture2d, 1);
}
public void OnNodeSelected(WindowNodeData data)
{
for (int i = 0; i < nodeDataList.Count; i++)
{
if (nodeDataList[i] == data)
{
continue;
}
nodeDataList[i].selected = false;
}
Repaint();
if (lastSelectedWindow != null)
{
lines.Add(new Tuple<WindowNodeData, WindowNodeData>(lastSelectedWindow, data));
}
lastSelectedWindow = data;
}
public void WindowNode(int windowId)
{
var data = nodeDataList[windowId];
GUI.DragWindow(new Rect(0, 0, data.rect.width, 16));
var curEvt = Event.current;
if (curEvt.type == EventType.MouseDown && curEvt.button == 0 &&
new Rect(0, 16, data.rect.width, data.rect.height - 16).Contains(curEvt.mousePosition))
{
data.selected = true;
OnNodeSelected(data);
}
if (data.selected)
{
EditorGUI.DrawRect(new Rect(0, 0, data.rect.width, data.rect.height), new Color(0.6f, 0, 0.4f, 0.3f));
}
GUILayout.Label(windowId.ToString());
}
}
}
边栏推荐
- Huawei interview summary during the epidemic
- C#课程设计之学生教务管理系统
- Golang的range
- Scite change background color
- GIS实战应用案例100篇(七十八)-多规合一数据库设计及数据入库
- Student educational administration management system of C # curriculum design
- Visual Studio (VS) shortcut keys
- 数据分析练习题
- 【更新中】微信小程序学习笔记_3
- Detailed explanation of all transfer function (activation function) formulas of MATLAB neural network
猜你喜欢

About Wireshark's unsuccessful installation of npcap

数据的存储

Mall management system of database application technology course design

Visual Studio (VS) shortcut keys

Creation of osgearth earth files to the earth ------ osgearth rendering engine series (1)

Redis的数据结构

详解sizeof、strlen、指针和数组等组合题

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

數據庫應用技術課程設計之商城管理系統

Simple demo of solving BP neural network by gradient descent method
随机推荐
[cloud native] introduction and use of feign of microservices
Editor Extensions
Notes on understanding applets 2022/7/3
C#课程设计之员工信息管理系统
Initial unity
UE4 call DLL
Wpf: solve the problem that materialdesign:dialoghost cannot be closed
Basic operation and process control 2
796 · unlock
P1596 [USACO10OCT]Lake Counting S
详解sizeof、strlen、指针和数组等组合题
C language - Introduction - essence Edition - take you into programming (I)
Puhua PLM empowers the whole scene product lifecycle management and helps the enterprise digital transformation of the main line of products
Unity change default editor
Image processing 8-cnn image classification
Map的实现类的顺序性
Storage of data
【音视频】ijkplayer错误码
Detailed explanation of all transfer function (activation function) formulas of MATLAB neural network
Introduction to Base64 coding