The PlayFab client API Task wrapper wraps the Unity client API to convert the async callback pattern to task async await pattern.
In most cases it would be preferrable to utilize the PlayFab C# SDK (Additional notes here) within Unity. This tool is most beneficial for projects that have already gone the Unity SDK route and are looking to gradually move code base to async await pattern.
Add the following line to your Unity package Packages/manifest.json
{
"dependencies": {
"com.breakstepstudios.playfab-client-api-task-wrapper": "https://github.com/Breakstep-Studios/playfab-client-api-task-wrapper.git#release",
}
}
/// <inheritdoc cref="PlayFabClientAPI.GetTitleData"/>
public static Task<PlayFabCommonResponse<GetTitleDataResult>> GetTitleDataAsync(
GetTitleDataRequest request)
{
var taskCompletionSource = new TaskCompletionSource<PlayFabCommonResponse<GetTitleDataResult>>();
PlayFabClientAPI.GetTitleData(request, (result) =>
{
taskCompletionSource.SetResult(new PlayFabCommonResponse<GetTitleDataResult>(result,null));
}, (error) =>
{
taskCompletionSource.SetResult(new PlayFabCommonResponse<GetTitleDataResult>(null, error));
});
return taskCompletionSource.Task;
}
public async PlayFabCommonResponse<GetTitleDataResult> GetTitleDataData()
{
var getTitleDataRequest = new GetTitleDataRequest
{
Keys = new List<string> { "Data" }
};
var result = await PlayFabClientAPIWrapper.GetTitleDataAsync(getTitleDataRequest);
if (result.ContainsError)
{
return result;
}
}