Loading Rankings
1. Copy the ranking UUID from BACKND Console
Go to BACKND Console and copy the UUID of the ranking created in BACKND Base > Ranking Management
.
2. Write a game information insertion method
Add content to the RankGet method in BackndRank.cs written in Pre-arrangements.
At this time, paste the UUID of the ranking copied in No. 1 as the rankUUID of the RankGet method.
Example: "<copied UUID value>" -> "4088f640-693e-11ed-ad29-ad8f0c3d4c70"
BackndRank.cs
Before editing
public void RankGet() {
// Adds content of Step 3. Loading Rankings
}
After editing
public void RankGet() {
string rankUUID = "<copied UUID value>"; // Example: "4088f640-693e-11ed-ad29-ad8f0c3d4c70"
var bro = Backnd.Leaderboard.Player.GetLeaderboard(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);
}
}
3. Add method call to BackndManager.cs
BackndManager, which is automatically called when the game is executed, must be used to call this method.
Add it so that the method may be called after BACKND initialization and BACKND login.
BackndManager.cs
Before editing(After Step 2. Ranking Registration)
async void Test() {
await Task.Run(() => {
BackndLogin.Instance.CustomSignIn("user1", "1234"); // BACKND login method
BackndRank.Instance.LeaderboardInsert(100); // [Addition] Ranking registration method
Debug.Log("Test complete.");
});
}
After editing
async void Test() {
await Task.Run(() => {
BackndLogin.Instance.CustomSignIn("user1", "1234"); // BACKND login method
BackndRank.Instance.RankGet(); // [Addition] Ranking loading method
Debug.Log("Test complete.");
});
}
4. Test in Unity
After editing the script, execute Unity debugging and check the console log of Unity.
The method has been successfully called when the log displays 'User information updated on the ranking'.
When errors, such as statusCode : 400, 404, and 409, occur instead of the above log being displayed, you can check which errors caused the failure in GetLeaderboard error case.
Error case
An error occurred while looking up rankings. : statusCode : 404
errorCode : NotFoundException
Change the copied UUID value in the first line of the method, string rankUUID = "Copied UUID value"; to the actual UUID of the ranking created in the console.