Author Topic: Delete item on drop  (Read 4907 times)

monogon

  • Newbie
  • *
  • Thank You
  • -Given: 3
  • -Receive: 0
  • Posts: 9
    • View Profile
Delete item on drop
« on: March 28, 2014, 06:04:33 AM »
Greetings!

I'm stuck at the moment trying to delete a DragDropItem on DragDropRelease. The draggable items are children of a UIGrid which is inside a window. Outside this window I specified a DragDropContainer and the parenting works fine -> I can drag the items out of the grid onto the new DragDropContainer so far.

But how can I read events from the DragDropItem to call additional methods? I think it's kind of trivial but I'm stuck...

I want the following to happen:
1. When the DragDropItem is dragged over the DragDropContainer window I want the Sprite of DragDropItem to turn red (indicating the deleting process).
2. When the item is actually released on the new DragDropContainer I want the DragDropItem to be deleted.

So how can I access these events? I don't need help with the deletion process itself but just need to know how to determine when the item has been released and which gameObject it has been released on.

I have a menuManager class which dynamically creates buttons and subscribes to the button onClick event
(pseudocode: EventDelegate.Add(newButton.onclick, certainMethodInMenuManagerClass) which works fine. I thought I could subscribe to the drag events likewise but the class does not seem to hold these events. :(

Is there an easy solution for this problem?

Thanks in advance!
 
« Last Edit: March 28, 2014, 06:12:16 AM by monogon »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Delete item on drop
« Reply #1 on: March 28, 2014, 10:00:09 AM »
You will get an OnDragOver notification on Object A when you drag Object B over it. Inside UICamera.currentTouch.dragged tells you what's being dragged, letting you modify it via your typical GetComponent<UISprite>() or what have you.

For an example of how to destroy an item, have a look at ExampleDragDropItem. It does that on line 41 after instantiating a 3D object.

monogon

  • Newbie
  • *
  • Thank You
  • -Given: 3
  • -Receive: 0
  • Posts: 9
    • View Profile
Re: Delete item on drop
« Reply #2 on: April 01, 2014, 10:36:22 AM »
Everything is working fine now!
Thank you!