반응형
플레이팹 로그인이 되었다는 가정하에 진행
공통
private void DisplayPlayfabError(PlayFabError error) => Debug.LogError("error : " + error.GenerateErrorReport());
저장
void SaveJsonToPlayfab()
{
DataContent content = new DataContent();
content.name = "안녕하세요";
content.value = 10;
content.isCheck = true;
Dictionary<string, string> dataDic = new Dictionary<string, string>();
dataDic.Add("DataContent", JsonUtility.ToJson(content));
SetUserData(dataDic);
}
public void SetUserData(Dictionary<string, string> data)
{
var request = new UpdateUserDataRequest() { Data = data, Permission = UserDataPermission.Public };
try
{
PlayFabClientAPI.UpdateUserData(request, (result) =>
{
Debug.Log("Update Player Data!");
}, DisplayPlayfabError);
}
catch (Exception e)
{
Debug.LogError(e.Message);
}
}
불러오기
public void GetUserData()
{
var request = new GetUserDataRequest() { PlayFabId = playfabId };
PlayFabClientAPI.GetUserData(request, (result) =>
{
foreach (var eachData in result.Data)
{
string key = eachData.Key;
if (eachData.Key.Contains("DataContent"))
{
DataContent content = JsonUtility.FromJson<DataContent>(eachData.Value.Value);
Debug.Log(content);
}
}
}, DisplayPlayfabError);
}
참고할만한 글
반응형