Skip to content

Wraps the PlayFab client API to return tasks (Consider using PlayFab C# SDK instead of this solution)

Notifications You must be signed in to change notification settings

Breakstep-Studios/playfab-client-api-task-wrapper

Repository files navigation

PlayFab Client API Task Wrapper

The PlayFab client API Task wrapper wraps the Unity client API to convert the async callback pattern to task async await pattern.

Usage Note

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.

Quick Start

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",
  }
}

Examples

Example Conversion

/// <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;
}

Example Usage

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;
    }
}

About

Wraps the PlayFab client API to return tasks (Consider using PlayFab C# SDK instead of this solution)

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages