A lot of people have been asking for tips on how to implement drag-drop functionality in Unity GUI scripting, so I decided to put together a reusable script for the purpose.
Basically the solution requires that your data class derives from GUIDraggableObject and at some point in its OnGUI method call Drag( Rect ) – just like GUI.Window handles dragging.
Right. Codez. First off the GUIDraggableObject.cs file:
An example data class inheriting from GUIDraggableObject – DataObject.cs:
And finally, this script demonstrates how you could have your data manager class use Unity GUI for data visualisation with drag-drop enabled – MyMonoBehaviour.cs:
Ah yea and an example of how you could do the same in an editor window – MyEditorWindow.cs: