|
|
|
using System;
|
|
|
|
using System.Collections;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using PlayFab;
|
|
|
|
using PlayFab.ClientModels;
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
public class PlayFabUserData : MonoBehaviour
|
|
|
|
{
|
|
|
|
|
|
|
|
public PlayerProfileModel myProfile;
|
|
|
|
public Dictionary<string, UserDataRecord> myCustomData;
|
|
|
|
|
|
|
|
public void GetPlayerUserData(string playfabID, Action<Dictionary<string,UserDataRecord>> onCallback, Action<string> onFallback)
|
|
|
|
{
|
|
|
|
var request = new GetPlayerCombinedInfoRequest
|
|
|
|
{
|
|
|
|
PlayFabId = playfabID, // Use the logged-in player's PlayFab ID
|
|
|
|
InfoRequestParameters = new GetPlayerCombinedInfoRequestParams
|
|
|
|
{
|
|
|
|
GetUserData = true // This will include User Data like AvatarID in the response
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
PlayFabClientAPI.GetPlayerCombinedInfo(request, result => onCallback(result.InfoResultPayload.UserData), result=>onFallback(result.ErrorMessage));
|
|
|
|
}
|
|
|
|
|
|
|
|
public void GetPlayerAvatarImage(string playfabID, Action<Sprite> onCallback, Action<string> onFallback)
|
|
|
|
{
|
|
|
|
var request = new GetPlayerCombinedInfoRequest
|
|
|
|
{
|
|
|
|
PlayFabId = playfabID, // Use the logged-in player's PlayFab ID
|
|
|
|
InfoRequestParameters = new GetPlayerCombinedInfoRequestParams
|
|
|
|
{
|
|
|
|
GetUserData = true // This will include User Data like AvatarID in the response
|
|
|
|
}
|
|
|
|
};
|
|
|
|
PlayFabClientAPI.GetPlayerCombinedInfo(request, result =>
|
|
|
|
{
|
|
|
|
if (result.InfoResultPayload.UserData != null &&
|
|
|
|
result.InfoResultPayload.UserData.ContainsKey("AvatarID"))
|
|
|
|
{
|
|
|
|
string avatarIdStr = result.InfoResultPayload.UserData["AvatarID"].Value;
|
|
|
|
int avatarIndex;
|
|
|
|
|
|
|
|
if (int.TryParse(avatarIdStr, out avatarIndex) &&
|
|
|
|
avatarIndex >= 0 && avatarIndex < PlayFabManager.Instance.avatarImages.Count)
|
|
|
|
{
|
|
|
|
Sprite dp = PlayFabManager.Instance.avatarImages[avatarIndex];
|
|
|
|
onCallback(dp);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Debug.LogWarning($"Invalid AvatarID value: {avatarIdStr}, falling back to default.");
|
|
|
|
onCallback(PlayFabManager.Instance.avatarImages[0]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
onCallback(PlayFabManager.Instance.avatarImages[0]);
|
|
|
|
}
|
|
|
|
}, result => onFallback(result.ErrorMessage));
|
|
|
|
|
|
|
|
//PlayFabClientAPI.GetPlayerCombinedInfo(request, result =>
|
|
|
|
//{
|
|
|
|
// if (result.InfoResultPayload.UserData != null && result.InfoResultPayload.UserData.ContainsKey("AvatarID"))
|
|
|
|
// {
|
|
|
|
// Sprite dp = PlayFabManager.Instance.avatarImages[
|
|
|
|
// int.Parse(result.InfoResultPayload.UserData["AvatarID"].Value)];
|
|
|
|
// onCallback(dp);
|
|
|
|
// }
|
|
|
|
// else
|
|
|
|
// onCallback(PlayFabManager.Instance.avatarImages[0]);
|
|
|
|
//}, result=>onFallback(result.ErrorMessage));
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|