using System.Collections;
using System.Collections.Generic;
using PlayFab.ClientModels;
using UnityEditor.PackageManager;
public class PlayfabManager : MonoBehaviour
public static PlayfabManager instance;
public void UserLogin(string _username, string _password)
var _request = new LoginWithPlayFabRequest()
PlayFabClientAPI.LoginWithPlayFab(
Debug.Log("Efetuando login com email!");
var _requestEmail = new LoginWithEmailAddressRequest()
PlayFabClientAPI.LoginWithEmailAddress(_requestEmail, UserLoginSuccess, UserLoginFail);
private void UserLoginSuccess(LoginResult result)
Debug.Log("Login Efetuado com sucesso!");
MenuController.instance.ShowScreen(MenuController.Screens.Loading);
PlayFabID = result.PlayFabId;
private void UserLoginFail(PlayFabError error)
Debug.Log("Erro: " + error.ErrorMessage);
MenuController.instance.ShowMessage("Erro: " + error.ErrorMessage);
MenuController.instance.ShowScreen(MenuController.Screens.Login);
public void UpdatePlayerScore(string _statisticName, int _score)
var _request = new UpdatePlayerStatisticsRequest
Statistics = new List<StatisticUpdate>
StatisticName = _statisticName,
PlayFabClientAPI.UpdatePlayerStatistics(_request,
Debug.Log("Ranking atualizado com sucesso!");
GetLeaderboard(_statisticName);
Debug.Log("Erro: " + error.ErrorMessage);
public void GetLeaderboard(string _statisticName)
var _request = new GetLeaderboardRequest
StatisticName = _statisticName,
PlayFabClientAPI.GetLeaderboard(_request,
MenuController.instance.UpdatePlayerRank(0);
foreach (var result in results.Leaderboard)
if (result.PlayFabId == PlayFabID)
Debug.Log("Jogador: " + PlayFabID + " - " + result.StatValue);
MenuController.instance.UpdatePlayerRank(result.StatValue);
_list += (result.Position + 1).ToString() + ": " + result.StatValue.ToString() + "\n";
MenuController.instance.UpdateRankingList(_list);
Debug.Log("Erro: " + error.ErrorMessage);