Skip to main content
Version: 6.0.0

Full Code

BackndRank.cs

using System.Collections.Generic;
using System.Text;
using UnityEngine;

// Adds BACKND SDK namespace
using BACKND;

public class BackndRank {
private static BackndRank _instance = null;

public static BackndRank Instance {
get {
if(_instance == null) {
_instance = new BackndRank();
}

return _instance;
}
}

public void LeaderboardInsert(int score) {
// [Change required] Change the 'copied UUID value' to the UUID value of the ranking created in 'BACKND Console > Ranking Management.'
string rankUUID = "Copied UUID value"; // Example: "4088f640-693e-11ed-ad29-ad8f0c3d4c70"

string tableName = "USER_DATA";
string rowInDate = string.Empty;

// The inDate value of the data used in the game data is required to insert a ranking.
// Therefore, you must load the data and extract its inDate value.
Debug.Log("Attempts data lookup.");
var bro = Backnd.PlayerTable.GetMyData(tableName);

if(bro.IsSuccess() == false) {
Debug.LogError("An error has occurred while looking up data : " + bro);
return;
}

Debug.Log("Data lookup successful : " + bro);

if(bro.FlattenRows().Count > 0) {
rowInDate = bro.FlattenRows()[0]["inDate"].ToString();
} else {
Debug.Log("The data does not exist. Attempting data insertion.");
var bro2 = Backnd.PlayerTable.Insert(tableName);

if(bro2.IsSuccess() == false) {
Debug.LogError("An error occurred while inserting data : " + bro2);
return;
}

Debug.Log("Data insertion successful : " + bro2);

rowInDate = bro2.GetInDate();
}

Debug.Log("rowInDate of my game information : " + rowInDate); // The extracted rowIndate value is as follows:

Param param = new Param();
param.Add("level", score);

// Edits the data with the extracted rowIndate to the param value and updates the data for the ranking.
Debug.Log("Attempting ranking insertion.");
var rankBro = Backnd.Leaderboard.Player.UpdateMyDataAndRefreshLeaderboard(rankUUID, tableName, rowInDate, param);

if(rankBro.IsSuccess() == false) {
Debug.LogError("An error has occurred while registering the ranking. : " + rankBro);
return;
}

Debug.Log("Successfully inserted the ranking. : " + rankBro);
}

public void RankGet() {
string rankUUID = "Copied UUID value"; // Example: "4088f640-693e-11ed-ad29-ad8f0c3d4c70"
var bro = Backnd.Leaderboard.Player.GetRankList(rankUUID);

if(bro.IsSuccess() == false) {
Debug.LogError("An error occurred while looking up rankings. : " + bro);
return;
}

Debug.Log("Ranking lookup successful. : " + bro);

Debug.Log("Total number of users registered to the ranking : " + bro.GetFlattenJSON()["totalCount"].ToString());

foreach(BACKND.LitJson.JsonData jsonData in bro.FlattenRows()) {
StringBuilder info = new StringBuilder();

info.AppendLine("Ranking : " + jsonData["rank"].ToString());
info.AppendLine("Nickname : " + jsonData["nickname"].ToString());
info.AppendLine("Score : " + jsonData["score"].ToString());
info.AppendLine("gamerInDate : " + jsonData["gamerInDate"].ToString());
info.AppendLine("Sort code : " + jsonData["index"].ToString());
info.AppendLine();
Debug.Log(info);
}
}
}

BackndManager.cs

using UnityEngine;
using System.Threading.Tasks;

// Adds BACKND SDK namespace
using BACKND;

public class BackndManager : MonoBehaviour {
void Start() {
var bro = Backnd.Initialize(); // Initialize BACKND

// Response value for BACKND initialization
if(bro.IsSuccess()) {
Debug.Log("Initialization successful : " + bro); // If successful, 'statusCode 204 Success'
} else {
Debug.LogError("Initialization failed : " + bro); // If failed, a 4xx statusCode error occurs
}

Test();
}

// A method that allows synchronous methods to be called from asynchronous methods(cannot be accessed by the Unity UI)
async void Test() {
await Task.Run(() => {
BackndLogin.Instance.CustomSignIn("user1", "1234"); // BACKND login method

BackndRank.Instance.LeaderboardInsert(100); // [Addition] Ranking registration method
BackndRank.Instance.RankGet(); // [Addition] Ranking loading method

Debug.Log("Test complete.");
});
}
}