Event Delegates

How to use API

The VIVEPORT AirSig Event Delegates provides an easy way for your content to handle event callback:

  • public delegate void OnGestureTriggered(long gestureId, GestureTriggerEventArgs eventArgs)

    Called when player triggered a gesture input, and this callback is called before processing the AirSig function.

    • gestureId: This id is associated with the input gesture data, you can use this to know this result callback is for which input.
  • public delegate void OnDeveloperDefinedMatch(long gestureId, string gesture, float score)

    Called when received an DeveloperDefined result.

    • gestureId: This id is associated with the input gesture data, you can use this to know this result callback is for which input.
    • gesture: The best match from candidates (the target list), see more in SetDeveloperDefinedTarget(List<string> target).
    • score: The match score of the best match, higher means higher confidence level, you can make a threshold to decide match or not. This value depends quality of samples collected during the collection phase. You could try out the value and adjust a best acceptable value. In normal situation, higher than 1 means match.
  • public delegate void OnPlayerSignatureTrained(long gestureId, Error error, float progress, SecurityLevel securityLevel)

    Called when the training progress result is sent.

    • gestureId: This id is associated with the input gesture data, you can use this to know this result is for which input.
    • error: error object with its error_code as below:
    • progress - indicates the training progress. It usually takes 3 - 7 cycles to complete the training.
    • securityLevel - indicates how difficult is the signature to duplicate by others according by the complexity of the signature higher value means higher security level, means more complex the signature is.
  • public delegate void OnPlayerGestureAdd(long gestureId, Dictionary<int, int> count)

    Called when player triggers a gesture and it’s stored in the cache. You must explicitly call SetPlayerGesture(index) in order to flush cache data to database.

    • gestureId: This id is associated with the input gesture data, you can use this to know this result is for which input.
    • count: a map of index id and cache count of gesture of this index.
  • public delegate void OnPlayerGestureMatch(long gestureId, int match)

    Called when a gesture is matched against with custom gesture.

    • gestureId: This id associated with the input gesture data, you can use this to know this result is for which input.
    • match: index that match, or -1 if controller data is invalid (for example, not moving).
  • public delegate void OnPlayerSignatureMatch(long gestureId, bool match, int targetIndex)

    Called when received an IdentifyPlayerSignature result.

    • gestureId: This id is associated with the input gesture data, you can use this to know this result callback is for which input.
    • match: The result is matched or not.
    • targetIndex: The id of the identity that been verified.
  • public delegate void OnSmartIdentifyDeveloperDefinedMatch(long gestureId, string gesture)

    Called when received a SmartIdentifyDeveloperDefinedMatch result.

    • gestureId: This id is associated with the input gesture data, you can use this to know this result callback is for which input.
    • gesture: the result matched gesture name.

VIVEPORT AirSig work flow

_images/AirSig_workflow.jpg

Example in Unity

Train Player Signature:

// Use Unity inspector to drag AirSigManager reference here
public AirSigManager airsigManager;

// Define callback for listening training progress
AirSigManager.OnPlayerSignatureTrained signatureTrained;

void HandleOnPlayerSignatureTrained(long gestureId, AirSigManager.Error error, float progress,
                                    AirSigManager.SecurityLevel securityLevel)
{
    // Handle training result
    if(1.0f >= progress)
        // training complete
    else
        // more gesture data is required
}

void Awake ()
{
    // 1. Use SetMode to configure AirSig function
    airsigManager.SetMode(AirSigManager.Mode.TrainPlayerSignature);

    // 2. Use SetTarget to configure index for train
    // or identification function
    airsigManager.SetTarget(100);

    // 3. Register callback for identification result
    signatureTrained = new AirSigManager.OnPlayerSignatureTrained(
                       HandleOnPlayerSignatureTrained);
    AirSigManager.onPlayerSignatureTrained += signatureTrained;
}

Use Developer-defined Gestures

Gesture profile must be generated first in AirSig Developer Portal.

  1. Once the gesture profile is generated, place it under Assets/StreamingAssets folder.
  2. Use SetClassifier to set the gesture profile name.
  3. Use SetDeveloperDefinedTarget to set the gesture name that we want to perform identification against.
  4. Use SetMode to set Mode.DeveloperDefined.
  5. Register Event Delegate to obtain the identification result.

Sample code that demostrates how to use developer predefined gesture and handle matched result using gesture profile in the SDK package:

// Use Unity inspector to drag AirSigManager reference here
public AirSigManager airsigManager;

// Define callback for listening Developer-defined Gesture match event
AirSigManager.OnDeveloperDefinedMatch developerGesture;

// Callback method that will handle the event
void HandleOnDeveloperDefinedMatch(long gestureId, string gesture, float score)
{
    // handle match or fail to match
}

void Awake ()
{
    // 1. Use SetMode to configure AirSig function
    airsigManager.SetMode(AirSigManager.Mode.DeveloperDefined);

    // 2. Set classifier and sub classifier
    airsigManager.SetClassifier("sample_gesture_profile", "");

    // 3. Use SetDeveloperDefinedTarget to configure
    // targets for identification function
    airsigManager.SetDeveloperDefinedTarget
    (
        new List {
            "C",
            "HEART",
            "DOWN" }
    );

    // 4. Register callback for identification
    // result
    developerGesture = new AirSigManager.OnDeveloperDefinedMatch(HandleOnDeveloperDefinedMatch);
    airsigManager.onDeveloperDefinedMatch += developerGesture;
}

For completed example, see Assets/Viveport/AirSig/Demo/Scene.