Search Unity

[NEW UPDATE!] Fingers - Touch Gestures - #1 in Quality, Support and Features : Dozens of Gestures✓

Discussion in 'Assets and Asset Store' started by jjxtra, Apr 25, 2016.

  1. jjxtra

    jjxtra

    Joined:
    Aug 30, 2013
    Posts:
    1,338
    That’s the right function. I think you want to add executing stage as well.
     
  2. Alf-Dee

    Alf-Dee

    Joined:
    May 12, 2016
    Posts:
    5
    Hi, I'm using fingers to detect both pan (virtual joystick) and swipe (up and down) to jump and crouch, but while it works in the editor, the swipe does not work at all when building on Android
    Code (CSharp):
    1.        
    2. private void OnEnable()
    3.         {
    4.             panGesture = new PanGestureRecognizer
    5.             {
    6.                 PlatformSpecificView = PanPlatformSpecificView,
    7.                 ThresholdUnits = PanGestureThresholdUnits
    8.             };
    9.             panGesture.StateUpdated += Panned;
    10.  
    11.             swipeGesture = new SwipeGestureRecognizer ();
    12.             swipeGesture.PlatformSpecificView = SwipeImage;
    13.             swipeGesture.ThresholdSeconds = SwipeThresholdSeconds;
    14.             swipeGesture.DirectionThreshold = 0;
    15.             swipeGesture.MinimumNumberOfTouchesToTrack = swipeGesture.MaximumNumberOfTouchesToTrack = SwipeTouchCount;
    16.             swipeGesture.EndMode = SwipeMode;
    17.             swipeGesture.StateUpdated += Swipe_Updated;
    18.  
    19.  
    20.             if (!string.IsNullOrEmpty(CrossPlatformInputHorizontalAxisName) && !string.IsNullOrEmpty(CrossPlatformInputVerticalAxisName))
    21.             {
    22.                 crossPlatformInputHorizontalAxisObject = FingersCrossPlatformInputReflectionScript.RegisterVirtualAxis(CrossPlatformInputHorizontalAxisName, out crossPlatformInputAxisMoveNewlyRegistered);
    23.                 crossPlatformInputVerticalAxisObject = FingersCrossPlatformInputReflectionScript.RegisterVirtualAxis(CrossPlatformInputVerticalAxisName, out crossPlatformInputAxisMoveNewlyRegistered);
    24.             }
    25.             if (!string.IsNullOrEmpty(CrossPlatformInputJumpAxisName))
    26.             {
    27.                 crossPlatformInputJumpAxisObject = FingersCrossPlatformInputReflectionScript.RegisterVirtualAxis(CrossPlatformInputJumpAxisName, out crossPlatformInputAxisJumpNewlyRegistered);
    28.             }
    29.             clearJumpAction = ClearJump;
    30.  
    31.  
    32.             FingersScript.Instance.AddGesture(panGesture);
    33.             FingersScript.Instance.AddGesture(swipeGesture);
    34.         }
    If I comment the "FingersScript.Instance.AddGesture(panGesture);" line, the swipe start working also on Android builds.

    My swipe method looks like that:
    Code (CSharp):
    1.         private void Swipe_Updated(DigitalRubyShared.GestureRecognizer gesture)
    2.         {
    3.  
    4.  
    5.             SwipeGestureRecognizer swipe = gesture as SwipeGestureRecognizer;
    6.             Debug.LogFormat("Swipe state: {0}", swipe.State);
    7.             if (swipe.State == GestureRecognizerState.Ended)
    8.             {
    9.                 float angle = Mathf.Atan2(-swipe.DistanceY, swipe.DistanceX) * Mathf.Rad2Deg;
    10.  
    11.                 Debug.LogFormat("Swipe dir: =====> {0}", swipe.EndDirection);
    12.  
    13.                 if (swipe.EndDirection == SwipeGestureRecognizerDirection.Up)
    14.                 {
    15.                     SwipeUpCallback.Invoke();
    16.                 }
    17.                 else if (swipe.EndDirection == SwipeGestureRecognizerDirection.Down)
    18.                 {
    19.                     SwipeDownCallback.Invoke();
    20.                 }
    21.             }
    22.         }
    What I notice from logcat is that "swipe.State" is never equal to GestureRecognizerState.Ended
    If I read the logs in the Unity console, the Ended states appears correctly.

    Can you help me please?
    Thanks in advance!
     
  3. jjxtra

    jjxtra

    Joined:
    Aug 30, 2013
    Posts:
    1,338
    Pan needs to be set to execute simultaneously with swipe.
     
  4. VolodymyrDrach

    VolodymyrDrach

    Joined:
    Dec 28, 2015
    Posts:
    7
    Hello! I am wondering if multi-finger touch can be implemented using this plugin? I'm interested in simultaneous touch. I want to make some unique beautiful swipe using multiple fingers.
     
  5. jjxtra

    jjxtra

    Joined:
    Aug 30, 2013
    Posts:
    1,338
    Of course. This is set up by default.
     
  6. VolodymyrDrach

    VolodymyrDrach

    Joined:
    Dec 28, 2015
    Posts:
    7
    Did you answer this question? "Hello! I am wondering if multi-finger touch can be implemented using this plugin? I'm interested in simultaneous touch. I want to make some unique beautiful swipe using multiple fingers." Show the diagram a picture of how to make a swipe with several fingers
     
  7. jjxtra

    jjxtra

    Joined:
    Aug 30, 2013
    Posts:
    1,338
    Yes, this is on by default. You can specify the max number and min number required fingers per gesture.
     
  8. anguyen2023

    anguyen2023

    Joined:
    Aug 21, 2021
    Posts:
    1
    Hi Jeff, I have this code right now for my AR application. How should I modify the Finger Rotate Scale for this object?
    Thank you!

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.XR.ARFoundation;
    5. using UnityEngine.EventSystems;
    6.  
    7. public class SpawnableManager : MonoBehaviour
    8. {
    9.     [SerializeField]
    10.     ARRaycastManager m_RaycastManager;
    11.     List<ARRaycastHit> m_Hits = new List<ARRaycastHit>();
    12.     [SerializeField]
    13.     public GameObject[] spawnable;
    14.  
    15.     Camera arCam;
    16.     GameObject spawnedObject;
    17.  
    18.     // Start is called before the first frame update
    19.     void Start()
    20.     {
    21.         spawnedObject = null;
    22.         // find by name, and the component of that GameObject
    23.         arCam = GameObject.Find("AR Camera").GetComponent<Camera>();
    24.     }
    25.  
    26.     // Update is called once per frame
    27.     private void SpawnPrefab(Vector3 spawnPosition)
    28.     {
    29.         if (ChangeToSphere.change)
    30.         {
    31.             spawnedObject = Instantiate(spawnable[1], spawnPosition, Quaternion.identity);
    32.         }
    33.         else
    34.         {
    35.             spawnedObject = Instantiate(spawnable[0], spawnPosition, Quaternion.identity);
    36.         }
    37.     }
    38.  
    39.     bool IsPointOverUIObject(Vector2 pos)
    40.     {
    41.         if (EventSystem.current.IsPointerOverGameObject())
    42.             return false;
    43.  
    44.         PointerEventData eventDataCurrentPosition = new PointerEventData(EventSystem.current);
    45.         eventDataCurrentPosition.position = new Vector2(pos.x, pos.y);
    46.         List<RaycastResult> results = new List<RaycastResult>();
    47.         EventSystem.current.RaycastAll(eventDataCurrentPosition, results);
    48.         return results.Count > 0;
    49.  
    50.     }
    51.     void Update()
    52.     {
    53.         if (Input.touchCount == 0)
    54.             return;
    55.  
    56.         RaycastHit hit;
    57.         Ray ray = arCam.ScreenPointToRay(Input.GetTouch(0).position);
    58.         if (!IsPointOverUIObject(Input.GetTouch(0).position) && m_RaycastManager.Raycast(Input.GetTouch(0).position, m_Hits)) // return True if there is at least one hit
    59.         {
    60.             if (Input.GetTouch(0).phase == TouchPhase.Began && spawnedObject == null)
    61.             {
    62.                 if (Physics.Raycast(ray, out hit))
    63.                 {
    64.                     if (hit.collider.gameObject.tag == "Spawnable")
    65.                     {
    66.                         spawnedObject = hit.collider.gameObject;
    67.                     }
    68.                     else
    69.                     {
    70.                         SpawnPrefab(m_Hits[0].pose.position);
    71.                     }
    72.                 }
    73.             }
    74.             else if (Input.GetTouch(0).phase == TouchPhase.Moved && spawnedObject != null)
    75.             {
    76.                 spawnedObject.transform.position = m_Hits[0].pose.position;
    77.             }
    78.             if (Input.GetTouch(0).phase == TouchPhase.Ended)
    79.             {
    80.                 spawnedObject = null;
    81.             }
    82.         }
    83.  
    84.     }
    85. }
    86.  
     
  9. JiachenZeng

    JiachenZeng

    Joined:
    May 18, 2021
    Posts:
    2
    Hi! I'm new to this. I imported the asset into a nearly empty Unity 2D project. And then it showed 2 errors. Could there be any setting wrong? I'm using Unity 2020.3.21f1 on Windows 10.

    Code (CSharp):
    1. Assets\Fingers\Demo\Scripts\DemoScriptPlaceObjects.cs(45,49): error CS0246: The type or namespace name 'GestureRecognizer' could not be found (are you missing a using directive or an assembly reference?)
    2. Assets\Fingers\Demo\Scripts\DemoScriptPlaceObjects.cs(22,16): error CS0246: The type or namespace name 'FingersPanOrbitComponentScript' could not be found (are you missing a using directive or an assembly reference?)
     
  10. jjxtra

    jjxtra

    Joined:
    Aug 30, 2013
    Posts:
    1,338
    I'm not seeing this. What fingers version are you running on?
     
  11. JiachenZeng

    JiachenZeng

    Joined:
    May 18, 2021
    Posts:
    2
    I just imported it yesterday and the version seems to be 3.0.3. Currently, I have installed Visual Studio with only Unity target. May this be the cause?

    And if I open and try to import, it doesn't show the proper class to be imported. Which GestureRecognizer it is? Windows.UI.Input.GestureRecognizer seems to be UWP which I didn't install.
    https://imgur.com/a/gr5L58O

    EDIT:
    I deleted the Library folder and reopened the project. Then it works fine. Seems to be a problem after upgrading the project version.
     
    Last edited: Nov 7, 2021
  12. Caffeen

    Caffeen

    Joined:
    Dec 25, 2013
    Posts:
    34
    Hi, apologies if this has been asked before; I didn't find what I was looking for by searching this thread.

    I'm having an issue where in Android builds, the FingerHandlerScript.Touches.Count never resets when my fingers are no longer touching the screen.

    It works fine in the editor; it returns 1 when the mouse button is held down, and returns to 0 when the button is released, but on my phone, touching the screen changes Touches.Count from 0 to 1 as expected, but when I remove my finger it remains at 1.
    Because of this, my 1-finger Pan gesture only works at the beginning. Once I've touched the screen with two fingers to use my 2-finger Pan gesture, the 1-finger Pan no longer works. Everything works as expected in the Editor.

    Strangely enough, switching to another app and back (Without restarting it) resets the Touches.Count back to 0 and I can use my 1-finger Pan again until I touch with two fingers.

    It's possible I've set the gestures up incorrectly? I based it on DemoScript.cs.

    I'm using 2019.4 and the new Input System. (I followed the instructions for it in the readme)

    Thanks in advance!
     
  13. jjxtra

    jjxtra

    Joined:
    Aug 30, 2013
    Posts:
    1,338
    Probably the first thing to try is does the old input system work?
     
  14. jjxtra

    jjxtra

    Joined:
    Aug 30, 2013
    Posts:
    1,338
    Are you still dealing with this error?
     
  15. Caffeen

    Caffeen

    Joined:
    Dec 25, 2013
    Posts:
    34
    Yes, I ran out of time and ended up having to change everything back to the old input system to make it work. Changing to the old input system made it work as expected with no additional tweaking of anything related to Fingers.
     
  16. jjxtra

    jjxtra

    Joined:
    Aug 30, 2013
    Posts:
    1,338
    I had to click on the event system in the scene and click a button to enable new input system functionality. Once I did that, the new input system started working as expected, I got taps and double taps in the tapdoubletap demo scene. I will add a note for this in the readme.
     
    Last edited: Nov 18, 2021
  17. jjxtra

    jjxtra

    Joined:
    Aug 30, 2013
    Posts:
    1,338
    Fingers Gestures 3.0.4 is now live on the asset store with fixes for touches when using the new input system.
     
unityunity