Author Topic: Drag drop from world to UI?  (Read 4234 times)

vexe

  • Full Member
  • ***
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 153
    • View Profile
Drag drop from world to UI?
« on: August 31, 2016, 09:26:13 AM »
Greetings,

We have a horizontal scrollview/inventory at the bottom of the screen where you can drag objects/train cars into the scene to build your train (2d game). Works fine. I want to go the other way around now. I want to click on a train car in the scene and be able to drag/drop it back to the UI.

One approach I could try is manually picking it up and handle moving it with the mouse and detect if it's released over the UI to add it back to the grid/inventory. Problem with that is depth. It will always appear behind the UI because of depth/sorting issues cause the UI renders on top.

The other approach which I'm trying now is to 'simulate' a UI drag. So when I click on a car in the scene, I 'instantly' add it to the grid, and then send an NGUI 'drag' event of some sort which will snap it to the mouse position and perform its drag.

But I'm not sure how to exactly achieve the latter. I tried calling 'StartDragging' from UIDragDropItem but it didn't do anything. Digging more into the code (UICamera) it seems I have to create a touch or mouse event? I'm not sure.

Maybe there is a better way of doing this?

Any ideas or pointers are appreciated?
Thanks.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Drag drop from world to UI?
« Reply #1 on: September 03, 2016, 01:50:01 AM »
What I did in my current game project is simple. When the drag operation is over the UI, I display a UI element. When the drag operation moves out of the UI, I hide the UI element and display a 3D game object. If the drag operation moves back onto the UI, I hide the 3D object and again show the UI element.