Author Topic: Start Drag on UIDragDropItem from another object  (Read 7403 times)

fsgj

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 2
    • View Profile
Start Drag on UIDragDropItem from another object
« on: September 08, 2016, 03:15:08 AM »
Hi,

I am having some trouble with starting the dragging process on a UIDragDropItem from another script. Here's the basic idea: I have a grid of objects (all UIDragDropitems) and above this grid I have an invisible UISprite with a collider which I want to use as a "Drag Panel" (to drag between pages, it uses an UIEventTrigger). What I want to do is, when the drag goes to either side, we start dragging the pages, but when I drag up, I want to drag the UIDragDropItem below.

The direction detection is done and working perfectly fine, but I can't start dragging the object. I've tried everything... I am also able to click the object behind the "Drag Panel" by disabling the "Drag Panel" and redoing the UICamera.Raycast and accessing it through UICamera.lastHit. This works flawlessly, but the dragging unfortunately I don't know how to tackle it.

I've tried:
- Changing the UICamera.selectedObject
- SendMessage("OnDragStart" / "OnPress" / "OnDragDropStart") on the UIDragDropItem
- Disabling the Drag Panel

Any ideas?

Thanks in advance.
- F

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Start Drag on UIDragDropItem from another object
« Reply #1 on: September 09, 2016, 02:45:04 PM »
The idea is not to call SendMessage, but to either disable components you don't want to react to events, or to call functions directly like UIDragScrollView does by calling scroll view's Drag() function directly.

It's not a good idea to have a big collider covering your content. It's better to have that collider be in the background (on the UIWidget, not a UISprite btw!). Any collider on the foreground should have similar scripts. This is why UIDragScrollView scripts exist on both the items in the drag & drop example, and the background sprite.

fsgj

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 2
    • View Profile
Re: Start Drag on UIDragDropItem from another object
« Reply #2 on: September 11, 2016, 08:01:38 PM »
Hi, thank you for the reply!

The thing is, I really do need to have the collider covering my content, because I need it it to, first and foremost, drag pages from left to right. I only want to activate the drag on the items below the collider if I drag up (to move them to a panel above). This is how I have it set up:

- UIRoot
  - Dragging Panel (w/ Collider & UIEventTrigger which I use to check when I am dragging and which direction, etc)
  - Item Grid
    - Items

I can't call Drag() or anything similar on my item if I drag up, there seems to be no function like this available publicly.

Thank you for your attention!
- F

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Start Drag on UIDragDropItem from another object
« Reply #3 on: September 13, 2016, 11:04:43 AM »
You can limit your drag up movement to be the drag's trigger, and ignore left to right movement. This is part of NGUI. Just examine the drag & drop example that comes with NGUI -- it does the opposite there. If you drag an item up and down, it scrolls the scroll view. If you drag an item left to right it will start dragging it.