2D Demo Scene

Play around with the simple demo scene to quickly understand the drag and drop function.

1. Open The DemoScene and Play It~

Path = [Assets/DragAndDrop/DemoScene/Simple Drag and Drop/DemoScene.unity]

DemoScene.unity

2. Demo Video - How To Add a Dragable Object

https://www.youtube.com/watch?v=RapRP0iHV5I

3. Demo Video - How To Add a DropSlot Object

https://www.youtube.com/watch?v=1fZ-WWdhdV4

- Drag and Drop Event Description -

You can simply add a new custom Drag and Drop Event in the inspector! Yeah!

Example Function Usage:

public void ShowDragInfo(DragObj dragObj){    
    Debug.Log("ObjName:" + dragObj.name + " | Status:" + dragObj.m_DragState);
}

- DropSlotDemo Inherient Description -

For more advance usage, you can write your own drop function by simply inherient the DropSlot script.

For example in the demo scene, we write a DropSlotDemo script which inherent the DropSlot, then override the OnDrop function.

public class DropSlotDemo : DropSlot
    {
        public DataInfoDemo dataInfoDemo;
        public bool isOverrideOnDrop = true;
        public override void OnDrop(PointerEventData eventData)
        {
            base.OnDrop(eventData);
            if (!isOverrideOnDrop) return;
            var model = (DataInfoDemo) DropObj.m_ObjInfoComponent;
            dataInfoDemo.Initialize(model);
        }
    }

You can get the info of the drag object by casting the DropObj.m_ObjInfoComponent.

Then, do whatever you want.

For example, we call an Initialize function which replace the slot image to the draggable object image.

Last updated

Was this helpful?