User Tools

Site Tools


manual:gestures:start

Detecting Gestures

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.

Locating the GestureRecognizers

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.

General Usage

To detect a specific gesture, you must:

  1. Add the corresponding GestureRecognizer component on an object in your scene
  2. Configure its various properties
  3. Listen to the events it generates and react to them accordingly

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:

  1. Using standard .NET delegate-based events. Each gesture recognizer exposes a .NET event that you can subscribe to from code.
  2. Using Unity's SendMessage() method
    • The gesture event is broadcast to all the other components on the same GameObject
    • The gesture event can also be forwarded to the scene object currently being interacted with (selection). This however requires the GestureRecognizer to be equipped with a Raycaster component in order to detect scene objects.

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.

Properties

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:

Settings

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.

Components

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.

Editor Tips

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!

manual/gestures/start.txt · Last modified: 2013/12/11 18:45 by wravaine