Please Select Your Location

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

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";

    static string LaunchAPPID = "VIVEPORT ID you want to launch";                 // the VIVEPORT ID of the content you would like go to
    static string LaunchStoreAPPID = "VIVEPORT ID you want to launch";            // the VIVEPORT ID of the content you would like go to
    static string LaunchData = "LaunchData";                                      // the launchdata of the content you would like go to

    const int SUCCESS = 0;

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

    void OnDestroy()
    {
        Api.Shutdown(ShutdownHandler);                            // release resource and teaddown the sdk service
    }

    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
        }
    }

    private static void ShutdownHandler(int nResult)              // the callback of Api.Shutdown()
    {
        if (nResult == SUCCESS)
        {
            Application.Quit();                                    // the response of Api.Shutdown() is success, close the content
        }
        else
        {
            return;                                                // the response of Api.Shutdown() is fail, could go error handling flow of content and close the 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);       // the response of Api.GetLicense() is success, user is allowed to use the content and keep going on the content flow.
            Deeplink.IsReady(IsReadyHandler);
        }

        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 IsReadyHandler(int nResult)
    {
        if (nResult == SUCCESS)
        {
            Debug.Log("VIVEPORT Deeplink.IsReady pass");
#if !UNITY_ANDROID
            // could use below 1 or 2 or combine API to go the the content or store detail page
            // 1. Deeplink.GoToApp(DeeplinkHandler, LaunchAPPID, LaunchData);             // if DRM is success, go to the content you'd like to go.
            // 2. Deeplink.GoToStore(DeeplinkHandler, LaunchStoreAPPID);                  // if DRM is success, go to the content detail page of the store.
            Deeplink.GoToAppOrGoToStore(DeeplinkHandler, LaunchStoreAPPID, LaunchData);
#else
            // could use below 1 or 2 or combine API to go the the content or store detail page
            // 1. Deeplink.GoToApp(new MyDeeplinkChecker(), LaunchAPPID, LaunchData);             // if DRM is success, go to the content you'd like to go.
            // 2. Deeplink.GoToStore(new MyDeeplinkChecker(), LaunchStoreAPPID);                  // if DRM is success, go to the content detail page of the store.
            Deeplink.GoToAppOrGoToStore(new MyDeeplinkChecker(), LaunchStoreAPPID, LaunchData);   // if DRM is success, use the API to automatically check to go to content of store detail page.
#endif
        }
        else
        {
            Debug.Log("VIVEPORT Deeplink.IsReady fail");          // the response of Deeplink.IsReady() is fail
        }
    }


#if !UNITY_ANDROID
    private static void DeeplinkHandler(int errorCode, string message)
    {
        if (errorCode == 0)
        {
            MainThreadDispatcher.Instance().Enqueue(() => {
                Debug.Log("Deeplink is successful");
            });
        }
        else
        {
            MainThreadDispatcher.Instance().Enqueue(() => {
                Debug.Log("Deeplink errorCode : " + errorCode + " ErrorMessage : " + message);
            });
        }
    }
#else
    class MyDeeplinkChecker : Deeplink.DeeplinkChecker
    {

        public override void OnSuccess()
        {
            Debug.Log("Deeplink is successful");    // Deeplink is success, don't need to do anything for the event.
        }

        public override void OnFailure(int errorCode, string errorMessage)
        {
            Debug.Log("Deeplink is failure ErrorCode : " + errorCode + "ErrorMessage : " + errorMessage);   // Deeplink is fail, to check if it is a network issue.
        }

    }
#endif
}