Xesto Example Tutorial

This tutorial explains how to integrate the Xesto Gesture Api.

Follow the instructions in the Xesto Wave Api documentation to setup the dependencies.

Download the Unity's example tutorial project from the Unity Assets Store.

All of the changes will be implemented in the PlayerController, located in the Script folder.

Import the library:

using XestoGestureApi;

Add the Xesto variable:

public class PlayerController : MonoBehaviour {
    public static Xesto xesto;

Add this line to the Start() method:

void Start() {
    xesto = new Xesto("<api key>");
}

Your ApiKey can be found in your account on the portal.

To view the logs, add Xesto logger to the Start() method:

void Start() {
    xesto = new Xesto("<api key>");
    Xesto.logger = (str) => {Debug.Log(str);};
}

Create at least 5 gestures with 10 examples in the portal. For example:

Define the variables for each gesture in the PlayerController:

    // Initialized to false until an event is triggered.
    private bool up = false;
    private bool down = false;
    private bool left = false;
    private bool right = false;
    private bool circle = false;

Add listeners for each gesture in the Start() method.

    xesto.AddListener("Up", () =>
    {
        up = true;
    });
    xesto.AddListener("Down", () =>
    {
        down = true;
    });
    xesto.AddListener("Left", () =>
    {
        left = true;
    });
    xesto.AddListener("Right", () =>
    {
        right = true;
    });
    xesto.AddListener("Circle", () =>
    {
        circle = true;
    });

Activate the Xesto Gesture Api in the Start() method:

void Start() {
    <...>
    xesto.Start();
}

To move the ball with your hand, replace this code in the FixedUpdate() method:

        float moveHorizontal = Input.get("Horizontal");
        float moveVertical = Input.get("Vertical");

to

        float moveHorizontal = 0f;
        float moveVertical = 0f;
        if (down == true){
            moveVertical = -5.0f;
            down = false;
        }
        if (up == true){
            moveVertical = 5.0f;
            up = false;
        }
        if (left == true){
            moveHorizontal = -1.0f;
            down = false;
        }
        if (right == true){
            moveHorizontal = 1.0f;
            up = false;
        }
        if (circle == true){
            moveHorizontal = 100.0f;
            circle = false;
        }

        <...>

        xesto.Update();

To ensure the proper execution, add onDestroy() method:

    private void OnDestroy(){
        xesto.Dispose();
    }