-
Notifications
You must be signed in to change notification settings - Fork 70
Open
Description
Hello, I read that you disable 'drag and drop' in the editor because of bugs and stuffs.
But to test out, it is not practical at all.
So I look for a way to drag and drop in the UnityEditor doc to propose alternative code when I am in the editor.
Code is a quick and dirty fix to make test. But you, someone that want to use your tool and reading this, can do it like this:
using System.Collections.Generic;
using UnityEngine;
using System.Linq;
using B83Win32;
using UnityEngine.Events;
#if UNITY_EDITOR_WIN
using UnityEditor;
#endif
public class FileDragAndDrop : MonoBehaviour
{
public UnityEvent m_onDropDetected;
public string[] m_filesDropped;
private string[] m_currentPathsHold;
public void Update()
{
#if UNITY_EDITOR_WIN
string[] paths = DragAndDrop.paths;
if (paths!=null && m_currentPathsHold!=null && paths.Length == 0 && m_currentPathsHold.Length > 0) {
m_filesDropped = m_currentPathsHold;
m_onDropDetected.Invoke();
}
m_currentPathsHold= paths;
#endif
}
void Awake ()
{
UnityDragAndDropHook.InstallHook();
UnityDragAndDropHook.OnDroppedFiles += OnFiles;
}
void OnDestroy()
{
UnityDragAndDropHook.UninstallHook();
}
void OnFiles(List<string> aFiles, POINT aPos)
{
m_filesDropped = aFiles.ToArray();
m_onDropDetected.Invoke();
}
}In hope to help.
(PS: Thanks for you code, it is very useful)
imsongkk
Metadata
Metadata
Assignees
Labels
No labels