-
Notifications
You must be signed in to change notification settings - Fork 70
Expand file tree
/
Copy pathFileDragAndDrop.cs
More file actions
38 lines (34 loc) · 1.05 KB
/
FileDragAndDrop.cs
File metadata and controls
38 lines (34 loc) · 1.05 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
using System.Collections.Generic;
using UnityEngine;
using System.Linq;
using B83.Win32;
public class FileDragAndDrop : MonoBehaviour
{
List<string> log = new List<string>();
void OnEnable ()
{
// must be installed on the main thread to get the right thread id.
UnityDragAndDropHook.InstallHook();
UnityDragAndDropHook.OnDroppedFiles += OnFiles;
}
void OnDisable()
{
UnityDragAndDropHook.UninstallHook();
}
void OnFiles(List<string> aFiles, POINT aPos)
{
// do something with the dropped file names. aPos will contain the
// mouse position within the window where the files has been dropped.
string str = "Dropped " + aFiles.Count + " files at: " + aPos + "\n\t" +
aFiles.Aggregate((a, b) => a + "\n\t" + b);
Debug.Log(str);
log.Add(str);
}
private void OnGUI()
{
if (GUILayout.Button("clear log"))
log.Clear();
foreach (var s in log)
GUILayout.Label(s);
}
}