Unity
                                
                                    
using UnityEngine;
using System;
using Viveport;
public class ViveportDemo : MonoBehaviour
{
   private int nInitValue = 0, nResult = 0;
#if UNITY_ANDROID
   private int nWidth = 150, nHeight = 100;
#else
   private int nWidth = 110, nHeight = 40;
#endif
   private int nXStart = 10, nYStart = 35;
   private string stringToEdit = "ID_Stat1";
   private string StatsCount = "80";
   private string achivToEdit = "ID_Achievement1";
   private static bool bInit = true, bIsReady = false;
   static string VIVEPORT_ID = "bd67b286-aafc-449d-8896-bb7e9b351876";
   // Use this for initialization
   void Start ()
   {
       Api.Init(InitStatusHandler, VIVEPORT_ID);
   }
   void OnGUI()
   {
       GUIStyle CustButton = new GUIStyle("button");
   #if UNITY_ANDROID
       CustButton.fontSize = 23;
   #endif
       if (bInit == false)
          GUI.contentColor = Color.white;
       else
          GUI.contentColor = Color.grey;
       // Init function
       if (GUI.Button(new Rect(nXStart, nYStart, nWidth, nHeight), "Init", CustButton))
       {
          if (bInit == false)
             Api.Init(InitStatusHandler, VIVEPORT_ID);
       }
       if (bInit == true)
          GUI.contentColor = Color.white;
       else
          GUI.contentColor = Color.grey;
       // Shutdown function
       if (GUI.Button(new Rect((nXStart + 1 * (nWidth + 10)), nYStart, nWidth, nHeight), "Shutdown", CustButton))
       {
          if (bInit == true)
             Api.Shutdown(ShutdownHandler);
       }
       // IsReady function
       if (GUI.Button(new Rect((nXStart + 2 * (nWidth + 10)), nYStart, nWidth, nHeight), "IsReady", CustButton))
       {
         if (bInit == true)
             UserStats.IsReady(IsReadyHandler);
       }
       /***************************************************************************/
       /*                          Stat sample code                               */
       /***************************************************************************/
       if (bInit == true && bIsReady == true)
          GUI.contentColor = Color.white;
       else
          GUI.contentColor = Color.grey;
       stringToEdit = GUI.TextField(new Rect(10, nWidth + 10, 120, 20), stringToEdit, 50);
       StatsCount = GUI.TextField(new Rect(130, nWidth + 10, 220, 20), StatsCount, 50);
       // DownloadStats function
       if (GUI.Button(new Rect(nXStart , nYStart + nWidth + 10, nWidth, nHeight),"DownloadStat"))
       {
           if (bInit == true && bIsReady == true)
              UserStats.DownloadStats(DownloadStatsHandler);
           else
              Viveport.Core.Logger.Log("Make sure init & isReady are successful.");
       }
       // UploadStats function
       if (GUI.Button(new Rect((nXStart + 1 * (nWidth + 10)), nYStart + nWidth + 10, nWidth, nHeight), "UploadState", CustButton))
       {
           if (bInit == true && bIsReady == true)
              UserStats.UploadStats(UploadStatsHandler);
           else
              Viveport.Core.Logger.Log("Make sure init & isReady are successful.");
       }
       // GetStat function
       if (GUI.Button(new Rect(nXStart + 2*(nWidth + 10), nYStart + nWidth + 10 , nWidth, nHeight), "GetStat", CustButton))
       {
           if (bInit == true && bIsReady == true)
           {
              nResult = UserStats.GetStat(stringToEdit, nInitValue);
              Viveport.Core.Logger.Log("Get " + stringToEdit + " stat name as => " + nResult);
           }
           else
              Viveport.Core.Logger.Log("Make sure init & isReady are successful.");
       }
       // SetStat function
       if (GUI.Button(new Rect(nXStart + 3* (nWidth + 10), nYStart + nWidth + 10, nWidth, nHeight), "SetStat", CustButton))
       {
           if (bInit == true && bIsReady == true)
           {
              Viveport.Core.Logger.Log("MaxStep is => " + int.Parse(StatsCount));
              nResult = int.Parse(StatsCount);
              UserStats.SetStat(stringToEdit, nResult);
              Viveport.Core.Logger.Log("Set" + stringToEdit + " stat name as =>" + nResult);
           }
           else
           {
              Viveport.Core.Logger.Log("Make sure init & isReady are successful.");
           }
       }
       /***************************************************************************/
       /*                          Achievement sample code                        */
       /***************************************************************************/
       achivToEdit = GUI.TextField(new Rect(10, 2* nWidth + 15, 120, 20), achivToEdit, 50);
       // GetAchievement function
       if (GUI.Button(new Rect(nXStart, nYStart + 2 * nWidth + 10, nWidth, nHeight), "GetAchieve", CustButton))
       {
           if (bInit == true && bIsReady == true)
           {
              bool bAchievement = false;
              bAchievement  = UserStats.GetAchievement(achivToEdit);
              Viveport.Core.Logger.Log("Get achievement => " + achivToEdit + " , and value is => "+ bAchievement);
           }
           else
              Viveport.Core.Logger.Log("Make sure init & isReady are successful.");
       }
       // SetAchievement function
       if (GUI.Button(new Rect(nXStart + nWidth + 10, nYStart + 2 * nWidth + 10, nWidth, nHeight), "SetAchieve", CustButton))
       {
           if (bInit == true && bIsReady == true)
           {
              UserStats.SetAchievement(achivToEdit);
              Viveport.Core.Logger.Log("Set achievement => " + achivToEdit);
           }
           else
              Viveport.Core.Logger.Log("Make sure init & isReady are successful.");
       }
       // ClearAchievement function
       if (GUI.Button(new Rect(nXStart + 2 * (nWidth + 10), nYStart + 2 * nWidth + 10, nWidth, nHeight), "ClearAchi", CustButton))
       {
           if (bInit == true && bIsReady == true)
           {
              UserStats.ClearAchievement(achivToEdit);
              Viveport.Core.Logger.Log("Clear achievement => " + achivToEdit);
           }
           else
              Viveport.Core.Logger.Log("Make sure init & isReady are successful.");
       }
       // GetAchievementUnlockTime function
       if (GUI.Button(new Rect(nXStart + 3 * (nWidth + 10), nYStart + 2 * nWidth + 10, nWidth, nHeight), "Achieve&Time", CustButton))
       {
           if (bInit == true && bIsReady == true)
           {
              int nunlockTime = 0;
              nunlockTime = UserStats.GetAchievementUnlockTime(achivToEdit);
              Viveport.Core.Logger.Log("The achievement's unlock time is =>" + nunlockTime);
           }
           else
           {
              Viveport.Core.Logger.Log("Make sure init & isReady are successful.");
           }
       }
   }
   private static void InitStatusHandler(int nResult)
   {
       if (nResult == 0)
       {
          bInit = true;
          bIsReady = false;
          Viveport.Core.Logger.Log("InitStatusHandler is successful");
       }
       else
       {
          bInit = false;
          Viveport.Core.Logger.Log("InitStatusHandler error : " + nResult);
       }
   }
   private static void IsReadyHandler(int nResult)
   {
       if (nResult == 0)
       {
          bIsReady = true;
          Viveport.Core.Logger.Log("IsReadyHandler is successful");
       }
       else
       {
          bIsReady = false;
          Viveport.Core.Logger.Log("IsReadyHandler error: " + nResult);
       }
   }
   private static void ShutdownHandler(int nResult)
   {
       if (nResult == 0)
       {
          bInit = false;
          bIsReady = false;
          Viveport.Core.Logger.Log("ShutdownHandler is successful");
       }
       else
       {
          Viveport.Core.Logger.Log("ShutdownHandler error: " + nResult);
       }
   }
   private static void DownloadStatsHandler(int nResult)
   {
       if (nResult == 0)
          Viveport.Core.Logger.Log("DownloadStatsHandler is successful ");
       else
          Viveport.Core.Logger.Log("DownloadStatsHandler error: " + nResult);
   }
   private static void UploadStatsHandler(int nResult)
   {
       if (nResult == 0)
          Viveport.Core.Logger.Log("UploadStatsHandler is successful");
       else
          Viveport.Core.Logger.Log("UploadStatsHandler error: " + nResult);
   }
}