-
Notifications
You must be signed in to change notification settings - Fork 0
Leaderboard
Jiufen edited this page Apr 2, 2021
·
3 revisions
We are going to take a look at the leaderboard functionality of playfab. This leaderboard only works with the playfab statistics, it doesn't work with the player data.
Like the previous parts of the wiki, we will create a request for the leaderboard and then we assign an onSuccess and an Onfailure callback:
public void GetLeaderBoard(){
var requestLeaderboard = new GetLeaderboardRequest{StartPosition = 0, StatisticName = "MaxScore", MaxResultsCount = 20};
PlayFabClientAPI.GetLeaderboard(requestLeaderboard,OnSuccessGetLeaderboard,OnFailureGetLeaderboard);
}
void OnSuccessGetLeaderboard(GetLeaderboardResult result){
foreach (PlayerLeaderboardEntry player in result.Leaderboard)
{
Debug.Log(player.DisplayName + ": " + player.StatValue);
}
}
void OnFailureGetLeaderboard(PlayFabError error){
Debug.LogError(error.GenerateErrorReport());
}If we want to show a display name for this games(not the username of the player but a new Display name for the game) we will need to set it up to the player, we could do this when the player sing up for the first time:
private void UpdateDisplayName(){
var requestUpdateDisplayName = new UpdateUserTitleDisplayNameRequest{DisplayName = username};
PlayFabClientAPI.UpdateUserTitleDisplayName(requestUpdateDisplayName, OnDisplayNameSuccess, LogPlayFabError);
}
private void OnDisplayNameSuccess(UpdateUserTitleDisplayNameResult result){
Debug.Log("Display Name: " + result.DisplayName);
}Home
C#
Game Design Patterns
- Command
- Flyweight pattern & Scriptable Objects
- Observer pattern
- State pattern
- Object Pool pattern
- Factory pattern
ECS
PlayFab
- Introduction
- Template Class
- Player Authentication
- Mobile Authentication
- Player Statistics
- Leaderboard
- Player Data
- Friends
Mirror