Unity编辑器 - DragAndDrop拖拽控件
Unity编辑器 - DragAndDrop拖拽控件
Unity编辑器的拖拽(DragAndDrop)在网上能找到的资料少,自己稍微研究了一下,写了个相对完整的案例,效果如下
代码:
object dragData = "dragData";
Vector2 offset;
Color col = new Color(1, 0, 0, 0.6f);
Rect rect1 = new Rect(20, 10, 100, 20);
Rect rect2 = new Rect(20, 60, 100, 20);
Rect drect;
bool isDraging;
int cid;
private void OnGUI() {
GUI.Box(rect1, "rect1");
GUI.Box(rect2, "rect2");
Event e = Event.current;
cid = GUIUtility.GetControlID(FocusType.Passive);
switch (e.GetTypeForControl(cid)) {
case EventType.MouseDown:
if (rect1.Contains(e.mousePosition))
GUIUtility.hotControl = cid;
break;
case EventType.MouseUp:
if (GUIUtility.hotControl == cid)
GUIUtility.hotControl = 0;
break;
case EventType.MouseDrag:
Debug.Log("MouseDrag");
if (GUIUtility.hotControl == cid && rect1.Contains(e.mousePosition)) {
DragAndDrop.PrepareStartDrag();
//DragAndDrop.objectReferences = new Object[] { };
DragAndDrop.SetGenericData("dragflag", dragData);
DragAndDrop.StartDrag("dragtitle");
offset = e.mousePosition - rect1.position;
drect = rect1;
isDraging = true;
e.Use();
}
break;
case EventType.DragUpdated:
Debug.Log("DragUpdated");
drect.position = e.mousePosition - offset;
if (rect2.Contains(e.mousePosition)) {
DragAndDrop.visualMode = DragAndDropVisualMode.Generic;
drect = rect2;
}
e.Use();
break;
case EventType.DragPerform:
Debug.Log("DragPerform");
DragAndDrop.AcceptDrag();
Debug.Log("DragPerform : " + DragAndDrop.GetGenericData("dragflag"));
e.Use();
break;
case EventType.DragExited:
Debug.Log("DragExited");
isDraging = false;
if (GUIUtility.hotControl == cid)
GUIUtility.hotControl = 0;
e.Use();
break;
}
if (isDraging) {
EditorGUI.DrawRect(drect, col);
}
}
事件调用顺序
Unity编辑器 - DragAndDrop拖拽控件的更多相关文章
- 【C#/WPF】GridSplitter 分割布局,拖拽控件分隔栏以改变控件尺寸
需求:界面由多部分控件组成,想要拖拽控件之间的分隔栏以改变尺寸. MainWindow.xaml: <Grid> <Grid.ColumnDefinitions> <Co ...
- Unity编辑器 - 鼠标悬停在控件上时改变鼠标样式
Unity编辑器 - 鼠标悬停在控件上时改变鼠标样式 摘自Unity文档 EditorGUIUtility.AddCursorRect public static void AddCursorRect ...
- Unity编辑器 - 使用GL绘制控件
Unity编辑器 - 使用GL绘制控件 控件较为复杂时,可能造成界面卡顿,在EditorGUI中也可以灵活使用GL绘制来提升性能. 以绘制线段为例: using UnityEngine; using ...
- flutter Draggable Widget拖拽控件
Draggable Widget Draggable控件负责就是拖拽,父层使用了Draggable,它的子元素就是可以拖动的,子元素可以实容器,可以是图片.用起来非常的灵活. 参数说明: data: ...
- Flutter 拖拽控件Draggable
Flutter提供了强大的拖拽控件,可以灵活定制,并且非常简单.下面作一个拖拽的案例. Draggable Widget Draggable控件负责就是拖拽,父层使用了Draggable,它的子元素就 ...
- ios-将代码创建的视图控件放入拖拽控件的下面
如图所示 图片是拖拽上去的imageView,橘黄色控件是在代码中创建的添加上去的,此时黄色view在imageView 上方 调用方法bringSubviewToFront:试图将imageView ...
- H5实现多图片预览上传,可点击可拖拽控件介绍
版权声明:欢迎转载,请注明出处:http://blog.csdn.net/weixin_36380516 在做图片上传时发现一个蛮好用的控件,支持多张图片同时上传,可以点击选择图片,也可以将图片拖拽到 ...
- Flutter 拖拽控件Draggable看这一篇就够了
注意:无特殊说明,Flutter版本及Dart版本如下: Flutter版本: 1.12.13+hotfix.5 Dart版本: 2.7.0 Draggable系列组件可以让我们拖动组件. Dragg ...
- 拖拽控件java版
Button vv = new Button("vvvv"); DragSource.getDefaultDragSource().createDefaultDragGestur ...
随机推荐
- 一款css3的标签动画效果
/*响应式设计,动画效果需引入animate.min.css库*/ <div class="index_tag"> <div class="rowFlu ...
- C# 委托系列(一)将方法作为方法的参数
委托 和 事件在 .Net Framework中的应用非常广泛,然而,较好地理解委托和事件对很多接触C#时间不长的人来说并不容易.它们就像是一道槛儿,过了这个槛的人,觉得真是太容易了,而没有过去的人每 ...
- Many-to-many relationships in EF Core 2.0 – Part 2: Hiding as IEnumerable
In the previous post we looked at how many-to-many relationships can be mapped using a join entity. ...
- 创建Cookie抛出异常:java.lang.IllegalArgumentException: Control character in cookie value
调用Cookie对象的构造函数可以创建Cookie.Cookie对象的构造函数有两个字符串参数:Cookie名字和Cookie值. 名字和值都不能包含空白字符以及下列字符:[ ] ( ) < ...
- mysql数据库迁移到oracle数据库后 如何删除相同的数据
mysql数据库迁移到oracle数据库后 如何删除相同的数据 首先搞清楚有多少数据是重复的 select pid from product group by pid having count(pid ...
- jQuery实现简单的拼图游戏
一,实现拼图的搭建: <div class="box"> <table id="table1" class="mytable&quo ...
- 第3章 jQuery中的DOM操作
parent() .parents().closest() 区别示例: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitiona ...
- 常用的JavaScript设计模式(二)Factory(工厂)模式
Factory通过提供一个通用的接口来创建对象,同时,我们还可以指定我们想要创建的对象实例的类型. 假设现在有一个汽车工厂VehicleFactory,支持创建Car和Truck类型的对象实例,现在需 ...
- 启动pip时,< Fatal error in launcher: Unable to create process using '"' >问题的原因及解决方法
根本原因 要启动的pip程序,中指定的python程序路径不对 实例分析 我的window电脑上同时安装了python2.7和python3.6,他们的安装路径如下图: 注意图python2.7中红线 ...
- 关于解决 https 网站无法加载 http 脚本
前几天刚配置好https网站 然后今天浏览发现自己网站的地图插件不见了 然后看了一下报错显示 然后百度搜索一番找到了解决办法 <meta http-equiv="Content-Sec ...