Author Topic: How to pinch  (Read 23856 times)

ranilian

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 24
    • View Profile
    • Industry Corporation
How to pinch
« on: April 20, 2012, 01:28:00 PM »
Hey Aren,

Is there a way to pinch to zoom in NGUI? Any built-in support for that or should we handle it on our own?

Thanks,
Rani

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: How to pinch
« Reply #1 on: April 20, 2012, 01:49:39 PM »
If you're talking about gesture recognition, FingerGestures plugin is what you're looking for. I didn't even try to re-invent that wheel. :)

cyrus104

  • Guest
Re: How to pinch
« Reply #2 on: June 29, 2012, 05:53:27 PM »
ArenMook, thanks and great product and support. We wanted to see how you would recommending integrating finger gestures with ngui. We would like to put swipe and some of the other gestures along with pinch on NGUI objects.

Thanks

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: How to pinch
« Reply #3 on: June 29, 2012, 10:15:08 PM »
I've never done it myself, but others have, so I'll wait for them to pitch in.

zazery

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 26
    • View Profile
Re: How to pinch
« Reply #4 on: July 02, 2012, 06:43:19 AM »
I've been using FingerGestures for non-NGUI objects but it should be pretty straightforward. They don't interfere with each other. You can use the toolbox scripts it comes with (uses SendMessage) and direct your gestures to a script that has access to the NGUI components to modify.

If you want FingerGestures to ignore touches that began by touching an NGUI object's collider just setup the global filter delegate. Here's a quick snippet to illustrate how to do this. My UI is on a layer called NGUI, which is layer 8.

  1. Camera NGUICamera;
  2.  
  3. bool FingerGesturesGlobalFilter( int fingerIndex, Vector2 position )
  4. {      
  5.         Ray ray = NGUICamera.ScreenPointToRay(new Vector3(position.x , position.y, 0));
  6.         return !Physics.Raycast(ray, 200, LayerMask.NameToLayer("NGUI"));
  7. }
  8.  
  9. void Start()
  10. {
  11.         NGUICamera = UICamera.FindCameraForLayer(8).camera; // function argument expect layer number; not mask
  12.         FingerGestures.GlobalTouchFilter = FingerGesturesGlobalFilter; // setup the delegate
  13. }
  14.  

joreldraw

  • Guest
Re: How to pinch
« Reply #5 on: July 03, 2012, 05:06:15 AM »
  1. if (Input.touchCount == 2 && Input.GetTouch(0).phase == TouchPhase.Moved && Input.GetTouch(1).phase == TouchPhase.Moved)
  2.        {
  3.  
  4.          curDist = Input.GetTouch(0).position - Input.GetTouch(1).position; //current distance between finger touches
  5.          prevDist = ((Input.GetTouch(0).position - Input.GetTouch(0).deltaPosition) - (Input.GetTouch(1).position - Input.GetTouch(1).deltaPosition)); //difference in previous locations using delta positions
  6.          touchDelta = curDist.magnitude - prevDist.magnitude;
  7.                
  8.                        
  9.  
  10.                  if ((touchDelta > 0)) // Out {}
  11.          
  12.                  if ((touchDelta < 0)) //In {}
  13.                
  14.                        
  15. }

kolchaud

  • Guest
Re: How to pinch
« Reply #6 on: September 17, 2012, 01:47:28 PM »
Hi everyone,

I use this code in my project :

Quote
Camera NGUICamera;

bool FingerGesturesGlobalFilter( int fingerIndex, Vector2 position )
{   
    Ray ray = NGUICamera.ScreenPointToRay(new Vector3(position.x , position.y, 0));
    return !Physics.Raycast(ray, 200, LayerMask.NameToLayer("NGUI"));
}

void Start()
{
    NGUICamera = UICamera.FindCameraForLayer(8).camera; // function argument expect layer number; not mask
    FingerGestures.GlobalTouchFilter = FingerGesturesGlobalFilter; // setup the delegate
}


And FingerGesturesGlobalFilter still return true, even if I visually touch NGUI widget (on NGUI layer). Did you set something on NGUI stuff ?

Thanks by advance for the reply

Dakcenturi

  • Guest
Re: How to pinch
« Reply #7 on: December 14, 2012, 08:36:10 PM »
I have a separate but related question.

If your whole screen is actually a GUI element (IE there isn't anywhere that is not a GUI element from NGUI) then this method won't work correct?

How would you get the pinch to zoom functionality from NGUI to work in such a circumstance?

jeldrez

  • Sr. Member
  • ****
  • Thank You
  • -Given: 8
  • -Receive: 4
  • Posts: 352
    • View Profile
Re: How to pinch
« Reply #8 on: March 26, 2013, 08:03:18 AM »
Sorry for reviving this old post, but I have a doubt related to FingerGestures and in their own forum the support isn't so good as here.
Did anyone knows how to resize the input to a specific size, because now it works but in the entire screen. I want an specific gesture in a specific place and size. How I do that?

SketchWork

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 44
    • View Profile
Re: How to pinch
« Reply #9 on: April 18, 2013, 04:22:48 PM »
If you make sure you update to the latest version 3.0 you can use the onPinch event and see what the user is pinching on and either carry on to return without doing anything.  This way you can restrict what the user can pinch on.

lai3d

  • Guest
Re: How to pinch
« Reply #10 on: May 24, 2013, 02:49:11 AM »
I've been using FingerGestures for non-NGUI objects but it should be pretty straightforward. They don't interfere with each other. You can use the toolbox scripts it comes with (uses SendMessage) and direct your gestures to a script that has access to the NGUI components to modify.

If you want FingerGestures to ignore touches that began by touching an NGUI object's collider just setup the global filter delegate. Here's a quick snippet to illustrate how to do this. My UI is on a layer called NGUI, which is layer 8.

  1. Camera NGUICamera;
  2.  
  3. bool FingerGesturesGlobalFilter( int fingerIndex, Vector2 position )
  4. {      
  5.         Ray ray = NGUICamera.ScreenPointToRay(new Vector3(position.x , position.y, 0));
  6.         return !Physics.Raycast(ray, 200, LayerMask.NameToLayer("NGUI"));
  7. }
  8.  
  9. void Start()
  10. {
  11.         NGUICamera = UICamera.FindCameraForLayer(8).camera; // function argument expect layer number; not mask
  12.         FingerGestures.GlobalTouchFilter = FingerGesturesGlobalFilter; // setup the delegate
  13. }
  14.  

it doesn't work either.

lai3d

  • Guest
Re: How to pinch
« Reply #11 on: May 24, 2013, 02:56:43 AM »
   bool FingerGesturesGlobalFilter( int fingerIndex, Vector2 position )
   {   
      RaycastHit hit = new RaycastHit();
      return !UICamera.Raycast(new Vector3(position.x , position.y, 0), ref hit);
   }

Use above code. It totally works.

zeus_82

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 6
    • View Profile
Re: How to pinch
« Reply #12 on: September 26, 2016, 07:50:47 AM »
TouchKit library is quite good and thorough for gesture work.
and it is free.

Can be found here: https://github.com/prime31/TouchKit