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 System.Collections;
using UnityEngine;
using Viveport;

public class ViveportSampleDRM : MonoBehaviour
{
    // Get a VIVEPORT ID and VIVEPORT Key from the VIVEPORT Developer Console. Please refer to here:
    // https://developer.viveport.com/documents/sdk/en/viveport_sdk/definition/get_viveportid.html

    static string VIVEPORT_ID = "VIVEPORT ID of the content";           // replace with developer VIVEPORT ID
    static string VIVEPORT_KEY = "VIVEPORT Key of the content";         // replace with developer VIVEPORT Key

    private const int SUCCESS = 0;
    private static bool bInitComplete = false;

    void Awake()
    {
        MainThreadDispatcher mainThreadDispatcher = GameObject.FindObjectOfType();
        if (!mainThreadDispatcher)
        {
            gameObject.AddComponent();
        }
    }

    void Start()
    {
        Api.Init(InitStatusHandler, VIVEPORT_ID);       // initialize VIVEPORT platform
        Invoke("CheckInitStatus", 10);                  // check that VIVEPORT Init succeeded
    }

    void OnDestroy()
    {
        Api.Shutdown(ShutdownHandler);
    }

    private static void InitStatusHandler(int nResult)          // The callback of Api.init()
    {
        if (nResult == SUCCESS)
        {
            Debug.Log("VIVEPORT init pass");
            Api.GetLicense(new MyLicenseChecker(), VIVEPORT_ID, VIVEPORT_KEY);    // the response of Api.Init() is success, continue using Api.GetLicense() API
            bInitComplete = true;
        }
        else
        {
            Debug.Log("VIVEPORT init fail");
            Application.Quit();
            return;                                             // the response of Api.Init() is fail
        }
    }
    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
        }
    }

    private void CheckInitStatus()
    {
        if (!bInitComplete)
        {
            Debug.LogWarning("Viveport init check fail");     // init requires VIVEPORT app installed and online connection
            Application.Quit();
        }
        else
            Debug.Log("Viveport init check pass");
    }

    class MyLicenseChecker : Api.LicenseChecker
    {
        public override void OnSuccess(long issueTime, long expirationTime, int latestVersion, bool updateRequired)
        {
            // the response of Api.GetLicense() is DRM success, user is allowed to use the content and continue with content flow
            Debug.Log("Viveport DRM pass");
            Debug.Log("issueTime: " + issueTime);
            Debug.Log("expirationTime: " + expirationTime);
            MainThreadDispatcher.Instance().Enqueue(SuccessAction());
        }

        public override void OnFailure(int errorCode, string errorMessage)
        {
            // the response of Api.GetLicense() is DRM fail, user is not allowed to use the content
            Debug.LogWarning("Viveport DRM fail:"+ errorCode + " Message :" + errorMessage);
            MainThreadDispatcher.Instance().Enqueue(FailAction());
        }

        // Use these methods to call Unity functions from the API callbacks on the main thread
        IEnumerator SuccessAction()
        {
            yield return null;
        }

        IEnumerator FailAction()
        {
            Application.Quit();
            yield return null;
        }
    }
}