- Home /
Editor MouseDrag issues
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: http://jqueryui.com/sortable/#default
Thanks!
Answer by karl_ · Oct 29, 2012 at 03:30 AM
Without seeing code it's hard to diagnose your issue, however I implemented this same drag-able list mechanic in SimpleSprite a long ways back. Relevant source code is available here: http://code.google.com/p/simplesprite/source/browse/trunk/_SimpleSprite/Editor/AnimationEditor.cs
Not sure what was going on. Seems like calling DragAndDrop.StartDrag() was the culprit. No idea why. Thanks for the code-share either way!
Answer by Leslie-Young · Jan 21, 2015 at 12:56 PM
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();
}
Your answer
Follow this Question
Related Questions
Updating Player Settings with code 2 Answers
Is there a way to mass assign materials? 4 Answers