FingerGestures

m

types

tap

swipe

long press

pinch/rotation

how to detect gesture

functions

library

diagram

diagram

core system

main chunk of the library and provides input detection through various gesture recognizers

comp

singleton

FingerGestures

Input

Mouse

mousePosition

=

Touches

stream

subscribe

function OnEnable(){FingerGestures.OnDragBegin += FingerGestures_OnDragBegin;}

DragAndDrop

.OnDragBegin

//pick dragObject with raycast

//disable sim and gravity

.OnDragMove

//convert finger position to world position

//center object on finger

.OnDragEnd

//resume sim

//dragObject = null; no longer dragging anything

...

r

Here, we subscribe to the 3 drag events in the OnEnable() method that is automatically called by Unity when our script gets enabled. The ”+=” notation is a syntactic sugar specific to .NET events. It simply means “call this method when that event is fired”. Here for instance, we tell the system to call the FingerGestures_OnDragBegin() method on our TutorialMethod1 instance when the OnDragBegin event located on the FingerGestures singleton is fired. In more technical terms, this FingerGestures_OnDragBegin() method is referred to as a callback method or event handler.The signature of the callback method you use to subscribe to an event must match the signature of this particular event. For instance, the OnDragEnd event expects a callback method with exactly one argument of type “Vector2” (for the finger position). Trying to subscribe to the OnDragEnd event using a method with a different signature will generate a compilation error.

unsubscribe

function OnDisable(){FingerGestures.OnDragBegin -= FingerGestures_OnDragBegin;}

...

r

When subscribing to events, it's also important to remember to unsubscribe from them when you no longer can or need/want to receive notifications from them. It is particularly important in the case of the FingerGesture singleton events, as it persists between scene transitions. If you do not unsubscribe from the events before your object is destroyed, the FingerGestures singleton will still have that object on its list of event recipients, and a null reference error will occur as a consequence. That is why we unsubscribe from the drag events in the OnDisable() method that is automatically called by the Unity engine when the script is disabled (which also happens before the host game object is destroyed).

interpreter

GestureRecognizer

trigger gesture event

OnFingersUpdated(Listener)

getfinger.position

toolbox

set of higher-level utility scripts

toolbox scripts include a drag & drop system, third person orbit and pinch-zoom camera script