程式碼範例
                                
                                    
 Unity
                                
                                    
/** Language: C# */
using UnityEngine;
using System;
using Viveport;
public class ViveportDemo : MonoBehaviour
{
   private int nInitValue = 0, nResult = 0;
   private int nWidth = 110, nHeight = 40;
   private int nXStart = 10, nYStart = 35;
   private string stringToEdit = "Input Stats name";
   private string StatsCount = "Input max index";
   private string leaderboardToEdit = "Input leaderboard name";
   private string leaderboardUserName = "Input user name";
   private string leaderboardScore = "Input score";
   private string achivToEdit = "Input achieve name";
   private static bool bInit = true, bIsReady = false, bArcadeIsReady = false;
   static string VIVEPORT_ID = "bd67b286-aafc-449d-8896-bb7e9b351876";
   // Use this for initialization
   void Start ()
   {
       Api.Init(InitStatusHandler, VIVEPORT_ID);
   }
   void OnGUI()
   {
       if (bInit == false)
          GUI.contentColor = Color.white;
       else
          GUI.contentColor = Color.grey;
       // Init function
       if (GUI.Button(new Rect(nXStart, nYStart, nWidth, nHeight), "Init"))
       {
          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"))
       {
          if (bInit == true)
             Api.Shutdown(ShutdownHandler);
       }
       // IsReady function
       if (GUI.Button(new Rect((nXStart + 4 * (nWidth + 10)), nYStart, nWidth, nHeight),
                      "ArcadeIsReady"))
       {
          if (bInit == true)
             ArcadeLeaderboard.IsReady(IsArcadeLeaderboardReadyHandler);
       }
       /***************************************************************************/
       /*                         ArcadeLeaderboard sample code                   */
       /***************************************************************************/
       if (bInit == true && bArcadeIsReady == true)
           GUI.contentColor = Color.white;
       else
           GUI.contentColor = Color.grey;
       leaderboardToEdit = GUI.TextField(new Rect(10, 4 * nWidth + 20, 160, 20), leaderboardToEdit,
                                         150);
       // DownloadLeaderboardScores function
       if (GUI.Button(new Rect(nXStart, nYStart + 4 * nWidth + 20, nWidth, nHeight), "DL Arca LB"))
       {
           if (bInit == true && bArcadeIsReady == true)
           {
               ArcadeLeaderboard.DownloadLeaderboardScores(DownloadLeaderboardHandler,
                                                           leaderboardToEdit,
                                                           ArcadeLeaderboard.LeaderBoardTimeRange.AllTime,
                                                           10);
               Viveport.Core.Logger.Log("DownloadLeaderboardScores");
           }
           else
           {
               Viveport.Core.Logger.Log("Please make sure init & isReady are successful.");
           }
       }
       leaderboardUserName = GUI.TextField(new Rect(10 + 160, 4 * nWidth + 20, 160, 20),
                                           leaderboardUserName, 150);
       leaderboardScore = GUI.TextField(new Rect(10 + 320, 4 * nWidth + 20, 160, 20),
                                        leaderboardScore, 50);
       // UploadLeaderboardScore function
       if (GUI.Button(new Rect(nXStart + 1 * (nWidth + 10), nYStart + 4 * nWidth + 20, nWidth, nHeight),
                      "UL Arca LB"))
       {
           if (bInit == true && bArcadeIsReady == true)
           {
               ArcadeLeaderboard.UploadLeaderboardScore(UploadLeaderboardScoreHandler,
                                                        leaderboardToEdit,
                                                        leaderboardUserName,
                                                        int.Parse(leaderboardScore));
               Viveport.Core.Logger.Log("UploadLeaderboardScore");
           }
           else
           {
               Viveport.Core.Logger.Log("Please make sure init & isReady are successful.");
           }
       }
       // GetLeaderboardScoreCount function
       if (GUI.Button(new Rect(nXStart + 2 * (nWidth + 10), nYStart + 4 * nWidth + 20, nWidth, nHeight),
                      "Get Arca Count"))
       {
           if (bInit == true && bArcadeIsReady == true)
           {
               nResult = ArcadeLeaderboard.GetLeaderboardScoreCount();
               Viveport.Core.Logger.Log("GetLeaderboardScoreCount=> " + nResult);
           }
           else
           {
               Viveport.Core.Logger.Log("Please make sure init & Arcade isReady are successful.");
           }
       }
       // GetLeaderboardScore function
       if (GUI.Button(new Rect(nXStart + 3 * (nWidth + 10), nYStart + 4 * nWidth + 20, nWidth, nHeight),
                               "Get Arca Score"))
       {
           if (bInit == true && bArcadeIsReady == true)
           {
               int nResult = (int)ArcadeLeaderboard.GetLeaderboardScoreCount();
               Viveport.Core.Logger.Log("GetLeaderboardScoreCount => " + nResult);
               for (int i = 0; i < nResult; i++) { Viveport.Leaderboard lbdata; lbdata = ArcadeLeaderboard.GetLeaderboardScore(i); Viveport.Core.Logger.Log("UserName = " + lbdata.UserName + ", Score = " + lbdata.Score + ", Rank = " + lbdata.Rank); } } else { Viveport.Core.Logger.Log("Please make sure init & isReady are successful."); } } // GetLeaderboardUserScore function if (GUI.Button(new Rect(nXStart + 4 * (nWidth + 10), nYStart + 4 * nWidth + 20, nWidth, nHeight), "Get AC UScore")) { if (bInit == true && bArcadeIsReady == true) { int nResult = (int)ArcadeLeaderboard.GetLeaderboardUserScore(); Viveport.Core.Logger.Log("GetLeaderboardUserScore=> " + nResult);
           }
           else
           {
               Viveport.Core.Logger.Log("Please make sure init & isReady are successful.");
           }
       }
       // GetLeaderboardUserRank function
       if (GUI.Button(new Rect(nXStart + 5 * (nWidth + 10), nYStart + 4 * nWidth + 20, nWidth, nHeight),
                      "Get AC URank"))
       {
           if (bInit == true && bArcadeIsReady == true)
           {
               int nResult = (int)ArcadeLeaderboard.GetLeaderboardUserRank();
               Viveport.Core.Logger.Log("GetLeaderboardUserRank=> " + nResult);
           }
           else
           {
               Viveport.Core.Logger.Log("Please 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("IsReadyHandler 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 DownloadLeaderboardHandler(int nResult)
    {
       if (nResult == 0)
          Viveport.Core.Logger.Log("DownloadLeaderboardHandler is successful");
       else
          Viveport.Core.Logger.Log("DownloadLeaderboardHandler error: " + nResult);
    }
    private static void UploadLeaderboardScoreHandler(int nResult)
    {
       if (nResult == 0)
          Viveport.Core.Logger.Log("UploadLeaderboardScoreHandler is successful.");
       else
          Viveport.Core.Logger.Log("UploadLeaderboardScoreHandler error : " + nResult);
    }
}