In FingerGestures, user gestures such as taps, swipes, drags and pinches are handled by a specific family of components: the GestureRecognizers. They typically process a sequence of touch inputs performed by the user and raise an event when a valid gesture pattern is detected.
This article provides a high-level overview of the common properties and usage of the various GestureRecognizers provided by FingerGestures.
Each type of gesture supported by the library has its own component script derived from the base GestureRecognizer component. The various GestureRecognizer scripts are located in the Plugins\FingerGestures\Scripts\Gesture Recognizers folder.
You are also accessible from the Component > FingerGestures > Gestures menu.
To detect a specific gesture, you must:
As part of the gesture event notification, the GestureRecognizer provides a single event data parameter containing all the information relevant to that particular gesture event, such as position, fingers list, velocity or selected scene object and also a reference to the GestureRecognizer that generated it.
A gesture recognizer has several ways of firing its events:
It is up to your own preference and requirements as to what method to use. The delegate-based event method is the most efficient, while the SendMessage approach is usually the most convenient one.
We will cover in more details how to use these events in the next sections of this manual.
Since the various gesture recognizers derive from the same base class, they share a common set of properties and functionality. As an example, we'll take a look at the properties of a TapRecognizer and SwipeRecognizer components placed on the same object:
As you can see, both components share some common settings: fingers setup, reset mode, event notification settings, references to additional components…
They also have unique settings specific to each type of gesture: the swipe gesture recognizer has distance thresholds, velocity and deviation properties while the tap gesture recognizer allows you to specify a maximum duration and multiple tap value.
Event Message Broadcasting
This section deals with the use of the SendMessage() method to notify other systems when a gesture event happens. You can use the Message Name property to specify the name of the method to invoke on the event receivers.
By default, the Message Target is set to the same object the GestureRecognizer component is placed on, but you can specify a different one if you wish.
In this section, you can enhance the GestureRecognizer by manually specifying additional components.
For instance, adding a ScreenRaycaster component will allow the GestureRecognizer to become aware of scene objects equipped with a collider, and reference them in the event data sent to the various gesture event listeners. It will also allow the recognizer to forward event messages to the scene object that the gesture is currently interacting with. Click here for more detailed information on interacting with objects.
Placing your cursor on top of each property field will display tooltips detailing what that property is for and how to use it.
Clicking the Copy Event To Clipboard button will copy to the clipboard the code required to detect that gesture's event (when using the SendMessage method). You can then simply paste the generated code directly in your own script and fill in the gaps!