Please Select Your Location
Australia
Österreich
België
Canada
Canada - Français
中国
Česká republika
Denmark
Deutschland
France
HongKong
Iceland
Ireland
Italia
日本
Korea
Latvija
Lietuva
Lëtzebuerg
Malta
المملكة العربية السعودية (Arabic)
Nederland
New Zealand
Norge
Polska
Portugal
Russia
Saudi Arabia
Southeast Asia
España
Suisse
Suomi
Sverige
台灣
Ukraine
United Kingdom
United States
Please Select Your Location
België
Česká republika
Denmark
Iceland
Ireland
Italia
Latvija
Lietuva
Lëtzebuerg
Malta
Nederland
Norge
Polska
Portugal
España
Suisse
Suomi
Sverige

Unity

using UnityEngine;
using System;
using Viveport;

/** Language: C# */
public class ViveportDemo : MonoBehaviour
{
   static string VIVEPORT_ID = "VIVEPORT ID of the content";
   static string VIVEPORT_KEY = "VIVEPORT Key of the content";
   string userToken;
   const SUCCESS = 0;

   void Start ()
   {
       Api.Init(InitStatusHandler, VIVEPORT_ID);                 // initialize VIVEPORT platform
   }

   private static void InitStatusHandler(int nResult)            // The callback of Api.init()
   {
       if (nResult == SUCCESS)
       {
          Api.GetLicense(new MyLicenseChecker(), VIVEPORT_ID, VIVEPORT_KEY);    // the response of Api.Init() is success, go on using Api.GetLicense() API
       }
       else
       {
          return;                                                // the response of Api.Init() is fail, could go error handling flow of content
       }
   }

   class MyLicenseChecker : Api.LicenseChecker
   {
       public override void OnSuccess(long issueTime, long expirationTime, int latestVersion, bool updateRequired)
       {
           Debug.Log("issueTime: " + issueTime);
           Debug.Log("expirationTime: " + expirationTime);

           Token.IsReady(IsTokenReadyHandler);                   // the response of Api.GetLicense() is success, user is allowed to use the content and keep going on the content flow
       }

       public override void OnFailure(int errorCode, string errorMessage)
       {
           // Application.Quit();                                // the response of Api.GetLicense() is fail, user is not allowed to use the content, and could go error handling flow of content
           // do some error flow fo content
       }
   }

   private static void IsTokenReadyHandler(int nResult)          // The callback of Token.IsReady()
   {
       if (nResult == SUCCESS)
       {
          Token.GetSessionToken(GetSessionTokenHandler);         // the response of Token.IsReady() is success, go on using Token.GetSessionToken() API.
       }
       else
       {
          return;                                                // the response of Token.IsReady() is fail, could go error handling flow of content
       }
   }

   private static void GetSessionTokenHandler(int nResult, string message)  // The callback of Token.GetSessionToken()
   {
       if (nResult == SUCCESS)
       {
          userToken = message;                                   // the responase of Token.GetSessionToken() is success, save the user token for usage, then go on the content flow
       }
       else
       {
          return;                                                // the responase of Token.GetSessionToken() is fail, could go error handling flow of content
       }
   }
}