Trying to make a sortable list in a unity editor window. Not sure if it’s a bug or not, but i had it working and now it suddenly doesn’t anymore.
The editor window calls DrawGUI() on the items in the list, and each item is a base c# class set to serializable. After I do the base drawing of the list item, it then handles events. MouseDrag is used to start the drag, while I also have a DragUpdated and DragPerform checks. For some reason, MouseDrag works until I call StartDrag, which halts execution of the application code until I release the mouse. At which point it does my debug.log()s from the MouseDrag function, and doesn’t call DragPerform.
Am I maybe missing some key ingredient in getting custom items to drag in the editor? The goal is to set up something like this: Sortable | jQuery UI
I know this is an old question but since a google search landed me here I thought I’d share what helped for me…
I realised that if I first dragged something from the hierarchy then my dragging code suddenly started working. Finally found that I need to set objectReferences even though I called PrepareStartDrag() and do not use objectReferences. Here is my exact code if it will help someone else debug their porblem…
if (Event.current.type == EventType.MouseDrag)
{
plyEdGUI.ClearFocus();
DragAndDrop.PrepareStartDrag();
DragAndDrop.objectReferences = new UnityEngine.Object[0];
DragAndDrop.paths = null;
DragAndDrop.SetGenericData("BloxBlockDefinitionData", gr.def);
DragAndDrop.StartDrag(gr.name);
Event.current.Use();
}