-
Notifications
You must be signed in to change notification settings - Fork 341
Expand file tree
/
Copy pathDragDropAreaExample.cs
More file actions
86 lines (74 loc) · 2.93 KB
/
DragDropAreaExample.cs
File metadata and controls
86 lines (74 loc) · 2.93 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
using CZToolKit.Core.Editors;
using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
using UnityObject = UnityEngine.Object;
namespace CZToolKit.Examples
{
public class DragDropAreaExample : EditorWindow
{
[MenuItem("Tools/DragDropArea")]
public static void Open()
{
GetWindow<DragDropAreaExample>();
}
SerializedObject serializedObject;
private void OnEnable()
{
serializedObject = new SerializedObject(this);
}
public List<UnityObject> objects = new List<UnityObject>();
private void OnGUI()
{
EditorGUILayout.PropertyField(serializedObject.FindProperty("objects"));
UnityObject obj = EditorGUILayoutExtension.DragDropAreaSingle(GUILayout.Height(50));
GUI.Box(GUILayoutUtility.GetLastRect(), "使用GUILayout方式绘制接收单个资源区域,无需指定Rect", "GroupBox");
if (obj != null)
{
objects.Add(obj);
serializedObject.ApplyModifiedProperties();
serializedObject.Update();
}
Rect r = GUILayoutUtility.GetRect(50, 50);
GUI.Box(r, "使用GUI方式绘制接收单个资源区域,需指定Rect", "GroupBox");
obj = EditorGUIExtension.DragDropAreaSingle(r);
if (obj != null)
{
objects.Add(obj);
serializedObject.ApplyModifiedProperties();
serializedObject.Update();
}
r = GUILayoutUtility.GetRect(50, 50);
GUI.Box(r, "使用GUI方式绘制接收单个资源区域,需指定Rect,自定义高亮色", "GroupBox");
obj = EditorGUIExtension.DragDropAreaSingle(r, Color.black);
if (obj != null)
{
objects.Add(obj);
serializedObject.ApplyModifiedProperties();
serializedObject.Update();
}
r = GUILayoutUtility.GetRect(50, 50);
GUI.Box(r, "使用GUI方式绘制接收单个资源区域,需指定Rect,自定义鼠标指针", "GroupBox");
obj = EditorGUIExtension.DragDropAreaSingle(r, DragAndDropVisualMode.Link);
if (obj != null)
{
objects.Add(obj);
serializedObject.ApplyModifiedProperties();
serializedObject.Update();
}
r = GUILayoutUtility.GetRect(50, 50);
GUI.Box(r, "使用GUI方式绘制接收多个个资源区域,需指定Rect,自定义高亮色和鼠标指针", "GroupBox");
UnityObject[] objs = EditorGUIExtension.DragDropAreaMulti(r, DragAndDropVisualMode.Link, new Color(0.3f, 0.58f, 0.7f, 0.3f));
if (objs != null)
{
foreach (var item in objs)
{
objects.Add(item);
}
serializedObject.ApplyModifiedProperties();
serializedObject.Update();
}
}
}
}