-
Notifications
You must be signed in to change notification settings - Fork 341
Expand file tree
/
Copy pathEditorGUIExtension_DragDropArea.cs
More file actions
111 lines (95 loc) · 3.87 KB
/
EditorGUIExtension_DragDropArea.cs
File metadata and controls
111 lines (95 loc) · 3.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#region 注 释
/***
*
* Title:
*
* Description:
*
* Date:
* Version:
* Writer: 半只龙虾人
* Github: https://github.com/HalfLobsterMan
* Blog: https://www.crosshair.top/
*
*/
#endregion
using UnityEditor;
using UnityEngine;
namespace CZToolKit.Core.Editors
{
public static partial class EditorGUIExtension
{
static readonly DragAndDropVisualMode dropVisualMode = DragAndDropVisualMode.Copy;
static readonly Color dragDropHighlightColor = new Color(0f, 1f, 1f, 0.3f);
public static DragAndDropVisualMode DropVisualMode { get { return dropVisualMode; } }
public static Color DragDropHighlightColor { get { return dragDropHighlightColor; } }
/// <summary> 绘制一个可接收拖拽资源的区域 </summary>
public static Object[] DragDropAreaMulti(Rect _rect)
{
return DragDropAreaMulti(_rect, DropVisualMode, DragDropHighlightColor);
}
/// <summary> 绘制一个可接收拖拽资源的区域 </summary>
public static Object[] DragDropAreaMulti(Rect _rect, DragAndDropVisualMode _dropVisualMode)
{
return DragDropAreaMulti(_rect, _dropVisualMode, DragDropHighlightColor);
}
/// <summary> 绘制一个可接收拖拽资源的区域 </summary>
public static Object[] DragDropAreaMulti(Rect _rect, Color _hightlightColor)
{
return DragDropAreaMulti(_rect, DropVisualMode, _hightlightColor);
}
/// <summary> 绘制一个可接收拖拽资源的区域 </summary>
public static Object[] DragDropAreaMulti(Rect _rect, DragAndDropVisualMode _dropVisualMode, Color _hightlightColor)
{
Event evt = Event.current;
if (!_rect.Contains(evt.mousePosition)) return null;
Object[] temp = null;
switch (evt.type)
{
case EventType.DragUpdated:
case EventType.DragPerform:
DragAndDrop.visualMode = _dropVisualMode;
if (evt.type == EventType.DragPerform)
{
DragAndDrop.AcceptDrag();
temp = DragAndDrop.objectReferences;
}
Event.current.Use();
break;
case EventType.Repaint:
if (DragAndDrop.visualMode == _dropVisualMode)
EditorGUI.DrawRect(_rect, _hightlightColor);
break;
default:
break;
}
return temp;
}
/// <summary> 绘制一个可接收拖拽资源的区域 </summary>
public static Object DragDropAreaSingle(Rect _rect)
{
return DragDropAreaSingle(_rect, DropVisualMode, DragDropHighlightColor);
}
/// <summary> 绘制一个可接收拖拽资源的区域 </summary>
public static Object DragDropAreaSingle(Rect _rect, DragAndDropVisualMode _dropVisualMode)
{
return DragDropAreaSingle(_rect, _dropVisualMode, DragDropHighlightColor);
}
/// <summary> 绘制一个可接收拖拽资源的区域 </summary>
public static Object DragDropAreaSingle(Rect _rect, Color _hightlightColor)
{
return DragDropAreaSingle(_rect, DropVisualMode, _hightlightColor);
}
/// <summary> 绘制一个可接收拖拽资源的区域 </summary>
public static Object DragDropAreaSingle(Rect _rect, DragAndDropVisualMode _dropVisualMode, Color _hightlightColor)
{
Object[] temp = DragDropAreaMulti(_rect, _dropVisualMode, _hightlightColor);
if (temp == null || temp.Length == 0) return null;
for (int i = temp.Length - 1; i >= 0; i--)
{
if (temp[i] != null) return temp[i];
}
return null;
}
}
}