Sunday, January 03, 2016

Notes on DragAndDrop in the Unity Editor

The documentation for the Unity DragAndDrop class is a little lacking, so here are the notes from my experiments into how the whole things works and integrates with OnGUI.


* If the current event in your OnGUI function is MouseDrag, first call:

DragAndDrop.PrepareStartDrag ()

then assign a value to DragAndDrop.objectReferences or DragAndDrop.paths and then call:

DragAndDrop.StartDrag(string title)

* If the current event is DragUpdated, you need to check if the drag operation can succeed or fail, then set:

DragAndDrop.visualMode = DragAndDropVisualMode.*

to an appropriate value. Important:If the drag operation could be accepted at this point, call:

DragAndDrop.AcceptDrag()

which will allow the DragPerform event to occur correctly if the mouse button is released.

* If the current event is DragPerform, the drag operation has succeeded and you can perform whatever logic is needed. No further DragAndDrop calls need to be made.

* If the current event is DragExited, you know that the drag operation has ended and you can perform any cleanup needed. Note: This event always occurs, even when DragPerform has completed.




No comments:

Popular Posts