Author Topic: multitouch with a scrollview  (Read 3969 times)

briangibson

  • Newbie
  • *
  • Thank You
  • -Given: 2
  • -Receive: 0
  • Posts: 26
    • View Profile
multitouch with a scrollview
« on: May 07, 2014, 01:07:47 AM »
I've got a scrollview that basically fills the entire screen. I want to make it so that if I do a multitouch gesture like a pinch-to-zoom via TouchKit, the NGUI touch doesn't happen. How can I effectively 'block' touches to NGUI if I get a 2 finger touch? I can't let the scrollview inadvertently scroll from 1 finger of a pinch gesture.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: multitouch with a scrollview
« Reply #1 on: May 08, 2014, 12:14:06 AM »
If you want to filter touches, then you need to write a custom input handler (UICamera.onCustomInput) rather than just having NGUI get them from Unity.

briangibson

  • Newbie
  • *
  • Thank You
  • -Given: 2
  • -Receive: 0
  • Posts: 26
    • View Profile
Re: multitouch with a scrollview
« Reply #2 on: May 08, 2014, 01:29:30 PM »
That's useful, but it still seems to be processing the touch events along with the custom events. wouldn't I need to bail out early, as per the suggestion here: http://www.tasharen.com/forum/index.php?topic=6615.msg32559#msg32559   ? Or, is there a static I would I need to nullify to prevent the touch event continuing down the chain? I tried this, but it didnt work:

  1.         public void CustomZoomEvent(){
  2.                 if(isTwoFingered){
  3.                         //do a custom thing with 2 finger touch instead, blocking ngui
  4.                         UICamera.current = null;
  5.                         UICamera.currentTouch = null;
  6.                         Debug.Log ("doing a thing!");
  7.                 }
  8.                 else{
  9.                         Debug.Log ("not doing a thing.");
  10.                 }
  11.         }
  12.  




briangibson

  • Newbie
  • *
  • Thank You
  • -Given: 2
  • -Receive: 0
  • Posts: 26
    • View Profile
Re: multitouch with a scrollview
« Reply #3 on: May 08, 2014, 01:35:02 PM »
This worked:
  1.         public bool CustomZoomEvent(){
  2.                 if(isTwoFingered){
  3.                         //do a custom thing with 2 finger touch instead, blocking ngui
  4.                         UICamera.current = null;
  5.                         UICamera.currentTouch = null;
  6.                         UICamera.mTouches.Clear();
  7.                         Debug.Log ("doing a thing!");
  8.                         return true;
  9.                 }
  10.                 else{
  11.                         return false;
  12.                         Debug.Log ("not doing a thing.");
  13.                 }
  14.         }

if i modified line 970 of UICamera to this:
  1.                 if (onCustomInput != null && onCustomInput()){ }
  2.                 else if (useTouch) ProcessTouches ();
  3.                 else if (useMouse) ProcessMouse();
  4.  

changed the delegate to return a bool, and made mTouches in UICamera public so that I could clear out any remaining accidental touches when I switch to the zoom event.
« Last Edit: May 08, 2014, 02:27:54 PM by briangibson »

briangibson

  • Newbie
  • *
  • Thank You
  • -Given: 2
  • -Receive: 0
  • Posts: 26
    • View Profile
Re: multitouch with a scrollview
« Reply #4 on: May 08, 2014, 02:08:55 PM »
@Aren: One of the biggest difficulties I've been having in NGUI's touch system is its global touch drag threshold. Oftentimes, I need to have a global touch sensitivity to be lower (about 0) for sensitive interactions, higher for interacting with things like zoom gestures, etc. It would be amazing if there was a way to override the touch sensitivity per-widget. What I've been doing lately is setting the global touch sensitivity to 0, but doing Vector2.Distance() checks OnPress() per widget. this is cumbersome and doesn't always work well for all widget types.