Leaderboards for VIVEPORT Arcade API

The VIVEPORT SDK supports persistent leaderboards with automatically ordered entries for Arcade. These leaderboards can be used to display the rankings in your content and the data is collect from same arcade franchise.

How to use Arcade Leaderboard API

Note

Remember that you should call Top Level API - Api.Init() then Arcade Leaderboard API - ArcadeLeaderboard.IsReady() API to setup the SDK library and client runtime. And you should call upload score API first then can call download API. And please remember to call Top Level API - Api.Shutdown() to teardown the library runtime after you finish using VIVEPORT SDK.

Download a Arcade Leaderboard

  1. Leaderboards for your title can be downloaded by calling DownloadLeaderboardScores().
  • LeaderBoardTimeRange is for the data you get is for AllTime.
  1. Then you can retrieve leaderboard scores by calling GetLeaderboardScore(), retrieve the leaderboard score count by calling GetLeaderboardScoreCount().
  2. You can retrieve current user’s score by calling GetLeaderboardUserScore().
  3. You can also retrieve current user’s ranking by calling GetLeaderboardUserRank(). But if user’s ranking is over maximum ranking , the return value will be -1.

Upload a Score

You can use UploadLeaderboardScore() to upload score changes.

Step by step: ViveportSwitch tool

Step by step: Leaderboards

First, you need to login to VIVEPORT.

  1. Before using the developer console, you must install VIVEPORT, and log in to your HTC Account.

    _images/ViveLogin.png
  2. Sign in to the developer console using your HTC Account and password.

    _images/DeveloperLogin.png
  3. On Developers console, on My Content -> Manage page, click Add new experience button to create an experiene to obtain VIVEPORT ID.

    _images/AddNewExperience.png
  4. After creating, you can get VIVEPORT ID from below screen:

    _images/AppID1.png
  5. Then use Add leaderboard button to create a new leaderboard.

    _images/Add_Leaderboard.png
  6. Fill in all fields for the new leaderboard: ( please refer Glossary in detail )

    _images/Leaderboard.png

Detailed Example in 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);
    }
}