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

/* Language: C# */
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 = "Input Stats name";
   private string StatsCount = "Input max index";
   private string leaderboardToEdit = "ID_Leaderboard1";
   private string leaderboardUserName = "Karl";
   private string leaderboardScore = "1000";
   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);
       }


       /***************************************************************************/
       /*                          Leaderboard sample code                        */
       /***************************************************************************/

       if (bInit == true && bIsReady == true)
          GUI.contentColor = Color.white;
       else
          GUI.contentColor = Color.grey;

       leaderboardToEdit = GUI.TextField(new Rect(10, 3 * nWidth + 20, 160, 20), leaderboardToEdit
                                                  , 150);

       // DownloadLeaderboardScores function for global around user data.
       if (GUI.Button(new Rect(nXStart, nYStart + 3 * nWidth + 20, nWidth, nHeight), "DL Around"
                      , CustButton))
       {
          if (bInit == true && bIsReady == true)
          {
             UserStats.DownloadLeaderboardScores(DownloadLeaderboardHandler, leaderboardToEdit,
                                                 UserStats.LeaderBoardRequestType.GlobalDataAroundUser,
                                                 UserStats.LeaderBoardTimeRange.AllTime, -5, 5);
             Viveport.Core.Logger.Log("DownloadLeaderboardScores");
          }
          else
             Viveport.Core.Logger.Log("Make sure init is successful.");
       }

       // DownloadLeaderboardScores for global data function.
       if (GUI.Button(new Rect(nXStart + 1 * (nWidth + 10), nYStart + 3 * nWidth + 20, nWidth,
                      nHeight), "DL not Around", CustButton))
       {
          if (bInit == true && bIsReady == true)
          {
             UserStats.DownloadLeaderboardScores(DownloadLeaderboardHandler, leaderboardToEdit,
                                                 UserStats.LeaderBoardRequestType.GlobalData,
                                                 UserStats.LeaderBoardTimeRange.AllTime, 0, 10);
             Viveport.Core.Logger.Log("DownloadLeaderboardScores");
          }
          else
             Viveport.Core.Logger.Log("Make sure init is successful.");
       }

       leaderboardScore = GUI.TextField(new Rect(10 + 160, 3 * nWidth + 20, 160, 20),
                                        leaderboardScore, 50);

       // UploadLeaderboardScore function.
       if (GUI.Button(new Rect(nXStart + 2 * (nWidth + 10), nYStart + 3 * nWidth + 20, nWidth,
                      nHeight), "Upload LB", CustButton))
       {
          if (bInit == true && bIsReady == true)
          {
             UserStats.UploadLeaderboardScore(UploadLeaderboardScoreHandler, leaderboardToEdit,
                                              int.Parse(leaderboardScore));
             Viveport.Core.Logger.Log("UploadLeaderboardScore");
          }
          else
             Viveport.Core.Logger.Log("Make sure init is successful.");
       }

       // GetLeaderboardScoreCount function.
       if (GUI.Button(new Rect(nXStart + 3 * (nWidth + 10), nYStart + 3 * nWidth + 20, nWidth,
                      nHeight), "Get LB count", CustButton))
       {
          if (bInit == true && bIsReady == true)
          {
             nResult = UserStats.GetLeaderboardScoreCount();
             Viveport.Core.Logger.Log("GetLeaderboardScoreCount=> " + nResult);
          }
          else
             Viveport.Core.Logger.Log("Make sure init is successful.");
       }

       // GetLeaderboardScore function.
       if (GUI.Button(new Rect(nXStart + 4 * (nWidth + 10), nYStart + 3 * nWidth + 20, nWidth,
                      nHeight), "Get DL data", CustButton))
       {
          if (bInit == true && bIsReady == true)
          {
             int nResult = (int)UserStats.GetLeaderboardScoreCount();

             Viveport.Core.Logger.Log("GetLeaderboardScoreCount => " + nResult);

             for (int i = 0; i  " + nResult);
          }
          else
             Viveport.Core.Logger.Log("Make sure init is successful.");
       }

       // GetLeaderboardDisplayType function.
       if (GUI.Button(new Rect(nXStart + 6 * (nWidth + 10), nYStart + 3 * nWidth + 20, nWidth,
                      nHeight), "Get Disp Type", CustButton))
       {
          if (bInit == true && bIsReady == true)
          {
             int nResult = (int)UserStats.GetLeaderboardDisplayType();
             Viveport.Core.Logger.Log("GetLeaderboardDisplayType=> " + nResult);
          }
          else
             Viveport.Core.Logger.Log("Make sure init is 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);
   }
}