-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDragAndDropEditorWindow
More file actions
89 lines (82 loc) · 2.78 KB
/
DragAndDropEditorWindow
File metadata and controls
89 lines (82 loc) · 2.78 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
using UnityEngine;
using UnityEditor;
using System.Collections;
using System.Collections.Generic;
public class DragAndDropEditorWindow : EditorWindow
{
[MenuItem("Window/Drag And Drop")]
public static void Open()
{
GetWindow<DragAndDropEditorWindow>(false, "DragDrop", true);
}
private void OnGUI()
{
if (Event.current.type == EventType.DragUpdated)
{
DragAndDrop.visualMode = DragAndDropVisualMode.Copy;
Event.current.Use();
}
else if (Event.current.type == EventType.DragPerform)
{
// To consume drag data.
DragAndDrop.AcceptDrag();
// GameObjects from hierarchy.
if (DragAndDrop.paths.Length == 0 && DragAndDrop.objectReferences.Length > 0)
{
Debug.Log("GameObject");
foreach (Object obj in DragAndDrop.objectReferences)
{
Debug.Log("- " + obj);
}
}
// Object outside project. It mays from File Explorer (Finder in OSX).
else if (DragAndDrop.paths.Length > 0 && DragAndDrop.objectReferences.Length == 0)
{
Debug.Log("File");
foreach (string path in DragAndDrop.paths)
{
Debug.Log("- " + path);
}
}
// Unity Assets including folder.
else if (DragAndDrop.paths.Length == DragAndDrop.objectReferences.Length)
{
Debug.Log("UnityAsset");
for (int i = 0; i < DragAndDrop.objectReferences.Length; i++)
{
Object obj = DragAndDrop.objectReferences[i];
string path = DragAndDrop.paths[i];
Debug.Log(obj.GetType().Name);
// Folder.
if (obj is DefaultAsset)
{
Debug.Log(path);
}
// C# or JavaScript.
else if (obj is MonoScript)
{
Debug.Log(path + "\n" + obj);
}
else if (obj is Texture2D)
{
}
}
}
// Log to make sure we cover all cases.
else
{
Debug.Log("Out of reach");
Debug.Log("Paths:");
foreach (string path in DragAndDrop.paths)
{
Debug.Log("- " + path);
}
Debug.Log("ObjectReferences:");
foreach (Object obj in DragAndDrop.objectReferences)
{
Debug.Log("- " + obj);
}
}
}
}
}