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.
CrowdControl/Assets/Scripts/Dev/PlayFab/PlayFabUserData.cs

53 lines
1.9 KiB
C#

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"))
{
Sprite dp = PlayFabManager.Instance.avatarImages[
int.Parse(result.InfoResultPayload.UserData["AvatarID"].Value)];
onCallback(dp);
}
else
onCallback(PlayFabManager.Instance.avatarImages[0]);
}, result=>onFallback(result.ErrorMessage));
}
}