Author Topic: Slightly different Drag and Drop  (Read 4081 times)

Dev.D

  • Guest
Slightly different Drag and Drop
« on: May 07, 2012, 06:51:48 AM »
Example 11 Drag and drop works pretty sweet. I want to do a modified Drag and Drop behaviour using NGUI.

I have a catalog list of items on screen represented by a UITable with Icons*. I want to drag an icon from this list to the world. Using the provided DragDrop mechanism  what happens is that the icon get removed from the list and gets dragged along with the mouse. I would like to change this and make the Catelog list itself immutable. On (pressing and) dragging an icon from the list an instance of that icon gets created and that gets dragged along the mouse instead.  I  manually send this new instance an OnPress to simulate the mouse button press. This doesn't seem to work, the OnDrag and Drop notifications from the system always go to the icon in the catalog list and not the newly created icon :(.

I think I may have over complicated this. Any ideas how to do this better?

* An Icon is just a parent Gameobject containing a UISprite. The parent GO has a DragDropItem script attached.
« Last Edit: May 07, 2012, 06:53:54 AM by Dev.D »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Slightly different Drag and Drop
« Reply #1 on: May 07, 2012, 10:37:34 AM »
Sending OnPress won't do you any good as the logic of what's currently being dragged is inside UICamera.

You can set the UICamera.currentTouch.pressed object in your DragDrop item's OnPress. Might need to set UICamera.currentTouch.current as well, play with it.

Dev.D

  • Guest
Re: Slightly different Drag and Drop
« Reply #2 on: May 08, 2012, 08:10:50 AM »
Thanks, I'll try that !