Author Topic: swiping/dragging detection on particular objects  (Read 4292 times)

Gillissie

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 48
    • View Profile
swiping/dragging detection on particular objects
« on: August 14, 2013, 05:15:08 PM »
I have multiple areas in my mobile UI that will require a swipe to go to the next page of stuff. For this reason, I need to be able to know which area was touched when the swipe happened, so only that area changes pages. I am having a hard time understanding how to detect this information with NGUI.

For each swipable area, I have created a box collider.

I've tried looking at UICamera.currentTouch, but I can't figure out how or when that is populated with data I need. I don't know if NGUI has any kind of built-in support for drag events on particular objects, without the actual dragging of the object (the collider shouldn't move - it only needs to detect the touch, and the distance moved while touching).

On other non-NGUI projects that I've done this kind of thing, it was easy to store which object was touched, and the mouse location of the original touch, and compare it to the current mouse location to get the drag distance, and have certain things react only if certain objects were initially touched.

Thanks!

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: swiping/dragging detection on particular objects
« Reply #1 on: August 15, 2013, 07:13:43 AM »
UICamera.currentTouch will hold the data about the current touch -- that is, this is only valid during NGUI callbacks such as OnPress, OnClick, OnDrag, etc.

Straight from UICamera.MouseOrTouch:
  1.                 public GameObject current;              // The current game object under the touch or mouse
  2.                 public GameObject pressed;              // The last game object to receive OnPress
  3.                 public GameObject dragged;              // The last game object to receive OnDrag
You're likely looking for UICamera.currentTouch.pressed. It will hold a reference to the object that received the original press.