You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
PlumberUltimateAds/Assets/Scripts/Dev/PlayFab/PlayFabLeaderboards.cs

68 lines
2.1 KiB
C#

using System;
using System.Collections.Generic;
using PlayFab;
using PlayFab.ClientModels;
using UnityEngine;
public class PlayFabLeaderboards : MonoBehaviour
{
public static string DisplayName;
public void UpdateLevelsCompleted(int levelsCompleted)
{
var request = new UpdatePlayerStatisticsRequest
{
Statistics = new List<StatisticUpdate>
{
new StatisticUpdate
{
StatisticName = GameConstants.LevelCompletedStatsKey,
Value = levelsCompleted
}
}
};
PlayFabClientAPI.UpdatePlayerStatistics(request, OnStatisticsUpdateSuccess, OnStatisticsUpdateFailure);
}
private void OnStatisticsUpdateSuccess(UpdatePlayerStatisticsResult result)
{
Debug.Log("Successfully updated player statistics!");
}
private void OnStatisticsUpdateFailure(PlayFabError error)
{
Debug.LogError("Failed to update player statistics: " + error.GenerateErrorReport());
}
public void GetLeaderboard(Action<List<PlayerLeaderboardEntry>> onSuccess, Action<PlayFabError> onFailure)
{
var request = new GetLeaderboardRequest
{
StatisticName = GameConstants.LevelCompletedStatsKey,
StartPosition = 0,
MaxResultsCount = 10
};
PlayFabClientAPI.GetLeaderboard(request, result => onSuccess(result.Leaderboard), onFailure);
}
public void SetDisplayName(string displayName)
{
var request = new UpdateUserTitleDisplayNameRequest
{
DisplayName = displayName
};
PlayFabClientAPI.UpdateUserTitleDisplayName(request, OnDisplayNameUpdateSuccess, OnDisplayNameUpdateFailure);
DisplayName = displayName;
}
private void OnDisplayNameUpdateSuccess(UpdateUserTitleDisplayNameResult result)
{
Debug.Log("Display name set successfully: " + result.DisplayName);
}
private void OnDisplayNameUpdateFailure(PlayFabError error)
{
Debug.LogError("Failed to set display name: " + error.GenerateErrorReport());
}
}