Hi,
It seems that when I create my own EditorWindow class and monitor the mouse and drag events the ‘MouseDrag’ event doesn’t act correctly when I first startup Unity. The first time I launch unity and attempt a drag and drop in my editor window I do not get a MouseDrag event until I let go of the mouse button (Instead of getting it when I first click and move the mouse). If, after that, I go in the ‘Hierarchy’ window and drag and drop anything, go back to my editor window all the events seem to work normally again until I restart Unity.
To test this I wrote the following script that, after creating an empty project, I put in Assets/Editor/MyEditorWindow.cs :
using UnityEngine;
using UnityEditor;
class MyEditorWindow : EditorWindow
{
bool m_dragging = false;
[MenuItem("Window/MyEditorWindow")]
public static void ShowWindow()
{
EditorWindow.GetWindow(typeof(MyEditorWindow));
}
void OnGUI()
{
Event e = Event.current;
if (m_dragging)
{
DragAndDrop.visualMode = DragAndDropVisualMode.Link;
}
if ((e.type == EventType.DragUpdated) ||
(e.type == EventType.MouseDown) ||
(e.type == EventType.MouseUp))
{
Debug.Log(e.type);
}
else if((e.type == EventType.DragExited) ||
(e.type == EventType.DragPerform))
{
m_dragging = false;
Debug.Log(e.type);
}
else if (e.type == EventType.mouseDrag)
{
DragAndDrop.PrepareStartDrag();
DragAndDrop.StartDrag("MyEditorWindow_drag");
Debug.Log(e.type);
m_dragging = true;
}
}
}
When I do a drag and drop in my window after starting Unity I get the following log :
- mouseDown
- mouseDrag (happens when I let go of the mouse button)
- DragExited
If I do a drag and drop in the ‘hierarchy’ window and try a drag and drop in my editor after that I get the expected :
- mouseDown
- mouseDrag
- DragUpdated (Many times)
- DragPerform
- DragExited
Anybody got any clues on how to solve this ?
Thanks