Skip to main content

Quick Start (Unity)

Supported Environment

  • The recommended Unity editor version is 2019.x.

  • Minimum supported Android API level is 23.

  • Target Android API level is 30.

  • Minimum supported iOS Version is 11.0.

  • Minimum Xcode version is 13.3.

  • Camera permission, Network permission and Network connected environment are required.

  • Build target to REAL DEVICE during the development process.

info

SeeSo SDK uses the front camera of the device)

  • For best performance, must check target architectures ARM64 (Android/iOS) and select Scripting Backend to IL2CPP (Android only).

Sample Project

Please go to the sample project page for the purpose of using it rather than implementing it.

Environment Set-ups

  • Check the Development key.
  • Check the SeeSo Unity package.
  • Check the unity editor has recommended version.
  • Check the Android Build Support module installation.
  • Check the iOS Build Support module installation.

Sample App Implementation

  1. Create the new unity project from unity editor.

    unity-quick-start-0

  2. Import the SeeSo Unity package to the project.

    unity-quick-start-1

  3. Implement initGazeTracker function in the Start() function to initialize GazeTracker immediately when the application is launched.

    • The first factor of the initGazeTracker function is the development key generated from the SeeSo Console.

    • The second factor of the initGazeTracker function is the initializationCallback.onInitialized delegate, to check the initialization result.

      // Start is called before the first frame update
      void Start()
      {
      GazeTracker.initGazeTracker("YOUR_DEVELOPMENT_LICENSE_KEY", onInitialized);
      }

      void onInitialized(InitializationErrorType error)
      {
      if (error == InitializationErrorType.ERROR_NONE)
      {
      // Now GazeTracker is initialized
      Debug.Log("onInitialized Success");
      }
      else
      {
      // GazeTracker is not initialized
      Debug.Log("onInitialized Fail with reason : " + error);
      }
      }
  4. Define GazeCallback.onGaze delegates, then call setGazeCallback function to register the GazeCallback.onGaze delegates.

    void Start()
    {
    GazeTracker.initGazeTracker("YOUR_DEVELOPMENT_LICENSE_KEY", onInitialized);
    }

    void onInitialized(InitializationErrorType error)
    {
    if (error == InitializationErrorType.ERROR_NONE)
    {
    // Now GazeTracker is initialized
    Debug.Log("onInitialized Success");

    // Set GazeCallback to GazeTrakcer
    GazeTracker.setGazeCallback(onGaze);
    }
    else
    {
    // GazeTracker is not initialized
    Debug.Log("onInitialized Fail with reason : " + error);
    }
    }

    void onGaze(GazeInfo gazeInfo)
    {
    Debug.Log("onGaze " + gazeInfo.timestamp + "," + gazeInfo.x + "," + gazeInfo.y + "," + gazeInfo.trackingState + "," + gazeInfo.eyeMovementState + "," + gazeInfo.screenState);
    }
  5. Implement startTracking to start the GazeTracker.

    void Start()
    {
    GazeTracker.initGazeTracker("YOUR_DEVELOPMENT_LICENSE_KEY", onInitialized);
    }

    void onInitialized(InitializationErrorType error)
    {
    if (error == InitializationErrorType.ERROR_NONE)
    {
    // Now GazeTracker is initialized
    Debug.Log("onInitialized Success");

    // Set GazeCallback to GazeTrakcer
    GazeTracker.setGazeCallback(onGaze);

    // Start Tracking
    GazeTracker.startTracking();
    }
    else
    {
    // GazeTracker is not initialized
    Debug.Log("onInitialized Fail with reason : " + error);
    }
    }

    void onGaze(GazeInfo gazeInfo)
    {
    Debug.Log("onGaze " + gazeInfo.timestamp + "," + gazeInfo.x + "," + gazeInfo.y + "," + gazeInfo.trackingState + "," + gazeInfo.eyeMovementState + "," + gazeInfo.screenState);
    }
  6. startTracking will be executed async. To get the correct execution result of the startTracking function, you should define StatusCallback.onStarted and StatusCallback.onStopped, then call setStatusCallback to register them to the GazeTracker.

    void Start()
    {
    GazeTracker.initGazeTracker("YOUR_DEVELOPMENT_LICENSE_KEY", onInitialized);
    }

    void onInitialized(InitializationErrorType error)
    {
    if (error == InitializationErrorType.ERROR_NONE){
    // Now GazeTracker is initialized
    Debug.Log("onInitialized Success");

    // Set StatusCallback to GazeTrakcer
    GazeTracker.setStatusCallback(onStarted, onStopped);

    // Set GazeCallback to GazeTrakcer
    GazeTracker.setGazeCallback(onGaze);

    // Start Tracking
    GazeTracker.startTracking();
    }
    else
    {
    // GazeTracker is not initialized
    Debug.Log("onInitialized Fail with reason : " + error);
    }
    }

    void onStarted()
    {
    Debug.Log("Tracking is started");
    }

    void onStopped(StatusErrorType error)
    {
    Debug.Log("Tracking is stopped with reason : " + error);
    }

    void onGaze(GazeInfo gazeInfo)
    {
    Debug.Log("onGaze " + gazeInfo.timestamp + "," + gazeInfo.x + "," + gazeInfo.y + "," + gazeInfo.trackingState + "," + gazeInfo.eyeMovementState + "," + gazeInfo.screenState);
    }
  7. At last, SeeSo Unity application requires camera permission. Initialize the GazeTracker with the initGazeTracker function after camera permission is allowed.

    #if UNITY_ANDROID
    using UnityEngine.Android;
    #elif UNITY_IOS
    using System.Runtime.InteropServices;
    #endif

    #if UNITY_IOS
    [DllImport("__Internal")]
    private static extern bool hasiOSCameraPermission();
    [DllImport("__Internal")]
    private static extern void requestiOSCameraPermission();
    #endif

    void Start()
    {
    #if UNITY_ANDROID
    if (HasCameraPermission())
    {
    GazeTracker.initGazeTracker("YOUR_DEVELOPMENT_LICENSE_KEY", onInitialized);
    }
    else
    {
    RequestCameraPermission();
    }
    #endif
    }

    bool HasCameraPermission()
    {
    #if UNITY_ANDROID
    return Permission.HasUserAuthorizedPermission(Permission.Camera);
    #elif UNITY_IOS
    return hasCameraPermission();
    #endif
    }

    void RequestCameraPermission()
    {
    #if UNITY_ANDROID
    Permission.RequestUserPermission(Permission.Camera);
    #elif UNITY_IOS
    requestCameraPermission();
    #endif
    }

    void OnApplicationFocus(bool focus)
    {
    if (HasCameraPermission())
    {
    GazeTracker.initGazeTracker("YOUR_DEVELOPMENT_LICENSE_KEY", onInitialized);
    }
    else
    {
    requestPermission();
    }
    }

Run

Android

  1. Select the platform of Unity editor as Android.
info

Build Setting > Platform > Android > Switch platform to Android)

  1. Set the Android Minimum API Level as 23.
info

(Project Setting > Player > Other Setting > Identification > Minimum API Level 23)

  1. Set the Android Target API Level as 30.
info

(Project Setting > Player > Other Setting > Identification > Target API Level 30)

  1. To get the log from the SDK, activate the development build.
info

(Build Setting > Platform > Android > Development Build)

  1. Don't forget that select Scripting Backend to IL2CPP and check target architectures ARM64.
info

(Project Setting > Player > Other Setting > Scripting Backend > IL2CPP)

info

(Project Setting > Player > Other Setting > Target Architectures > ARM64)

  1. Connect the android device to PC.

  2. Build & Run.

info

(Build Setting > Build And Run)

  1. After the run, the Unity editor will display the gaze tracking data logs. 🎉

iOS

  1. Select the platform of Unity editor as iOS.
info

(Build Setting > Platform > iOS > Switch platform to iOS)

  1. Anything must be included in the camera permission description field.
info

(Project Setting > Player > Other Setting > Camera Usage Description)

  1. Set the iOS Target SDK as Device.
info

(Project Setting > Player > Other Setting > Target SDK > Device SDK)

  1. Set the iOS Target Minimum iOS version as 11.0.
info

(Project Setting > Player > Other Setting > Target Minimum OS version 11.0)

  1. To get the log from the SDK, activate the development build.
info

(Build Setting > Platform > iOS > Development Build)

  1. Don't forget that Check target architectures ARM64.
info

(Project Setting > Player > Other Setting > Architecture > ARM64)

  1. Connect the iOS device to PC.

  2. Build.

info

(Build Setting > Build)

  1. After the build, Xcode Project will be created. This project only can be used by signing in Xcode.

  2. Open and Build and then run the current scheme the xcode project.

  3. After the run, the Xcode editor will display the gaze tracking data logs 🎉

Preview for Android

  1. The camera preview used by the Android SDK is TextureView, which only works when hardware acceleration is enabled. unity-quick-start-3

  2. By default, Unity does not use hardware acceleration, so it must export Android Project to modify Android Menifest. unity-quick-start-4

  3. Modify the hardwareAccelerated attribute of activity tag to true in AndroidManifest.xml of unityLibrary module unity-quick-start-5

  4. To build and run the app, press arrow button unity-quick-start-6