Tasharen Entertainment Forum

Support => NGUI 3 Support => Topic started by: monogon on March 28, 2014, 06:04:33 AM

Title: Delete item on drop
Post by: monogon 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!
 
Title: Re: Delete item on drop
Post by: ArenMook 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.
Title: Re: Delete item on drop
Post by: monogon on April 01, 2014, 10:36:22 AM
Everything is working fine now!
Thank you!