forked from Bunny83/UnityWindowsFileDrag-Drop
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFileDragAndDrop.cs
30 lines (27 loc) · 898 Bytes
/
FileDragAndDrop.cs
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
using System.Collections.Generic;
using UnityEngine;
using System.Linq;
using B83.Win32;
public class FileDragAndDrop : MonoBehaviour
{
// important to keep the instance alive while the hook is active.
UnityDragAndDropHook hook;
void OnEnable ()
{
// must be created on the main thread to get the right thread id.
hook = new UnityDragAndDropHook();
hook.InstallHook();
hook.OnDroppedFiles += OnFiles;
}
void OnDisable()
{
hook.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.
Debug.Log("Dropped "+aFiles.Count+" files at: " + aPos + "\n"+
aFiles.Aggregate((a, b) => a + "\n" + b));
}
}