Author Topic: Drag Drop Swap - Request for a little coding  (Read 485 times)

tomraegan

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 2
    • View Profile
Drag Drop Swap - Request for a little coding
« on: December 22, 2017, 07:51:43 PM »
Hi!

I've been loving playing with NGUI for the past couple of weeks and am thrilled with the results. I don't expect anyone to just jump at the opportunity, but I'm going to ask anyways ;) I've read pretty much every thread containing OnDragDropRelease, but with no luck.

I've got a Playmaker/NGUI calculator going and it all works just fine.

1. Drag gameobject from scrollview to a container and drop.
2. Drag a new gameobject to the container and drop.
3. Have the two gameobjects swap, with the original icon returning to its scrollview.

The problem, of course, is that the second gameobject is dropping onto the first. As a result, the OnDrop event is hitting the first gameobject, not the container. I understand that this is deliberate. I cannot find a way in Playmaker to circumvent this and nor can I code. I've looked at the ExampleDragDropItem script and cannot penetrate its mysteries.

Could someone please modify that script or create a new one to achieve a swap of gameobjects under the circumstances described?

ps. I appreciate that this is beyond the purview of support and have no expectation of the dev replying. I'm reaching out to the community instead.

Much obliged.

tomraegan

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 2
    • View Profile
Re: Drag Drop Swap - Request for a little coding
« Reply #1 on: December 31, 2017, 03:14:19 AM »
Whilst I have been unable to produce my desired 'swap' outcome, I've come up with a workable alternative.

Using an OnHover event contained within each droppable gameobject, the target location now rejects all droppable objects except for the one currently inside it.

This means that there is no swap. Instead, the user will need to return the object in the target slot to its original place before dragging and dropping the alternative.

I am still interested in a coded version, if any coder happens to be interested.

Happy new year!