PlayFab Saving & Loading

You first need to authenticate user, so you can Login the user by using any way you like, for example, you can login the user using Email and Password:

public void Login ()
{
    Debug.Log ( "Logging..." );

    // Disable login button.
    var request = new LoginWithCustomIDRequest ();
    request.CreateAccount = true;
    request.CustomId = "User name here";

    // Send the request.
    PlayFabClientAPI.LoginWithCustomID ( request, OnLoginSuccess, OnLoginFailure );
}

void OnLoginSuccess ( LoginResult result )
{

    // Disable login button and enable other buttons
    Debug.Log ( "Login Successful" );
}

void OnLoginFailure ( PlayFabError error )
{

    // Disable all buttons except login button
    Debug.LogError ( "Login Failed" );
    Debug.LogError ( error.GenerateErrorReport () );
}

And then, you can save and load data:

public void Save ()
{
    Debug.Log ( "Saving..." );

    // Disable save button.
    SaveGamePlayFab playFab = new SaveGamePlayFab ();
    playFab.saveResultCallback = OnSaveSuccess;
    playFab.saveErrorCallback = OnSaveFailure;

    // Send the request.
    StartCoroutine ( playFab.Save ( "helloWorld", "Hello World" ) );
}

void OnSaveSuccess ( UpdateUserDataResult result )
{
    Debug.Log ( "Save Successful" );
}

void OnSaveFailure ( PlayFabError error )
{
    Debug.LogError ( "Save Failed" );
    Debug.LogError ( error.GenerateErrorReport () );
}

Note: You can use both Coroutines and Callbacks for using Save Game Pro PlayFab API, but in this example we are using Callbacks instead of Coroutines.

Now, let us load the data:

public void Load ()
{

    // We first need to download the data and then load from the downloaded data.
    Debug.Log ( "Loading..." );

    m_DownloadPlayFab = new SaveGamePlayFab ();
    m_DownloadPlayFab.downloadResultCallback = OnDownloadSuccess;
    m_DownloadPlayFab.downloadErrorCallback = OnDownloadFailure;

    // Send the request.
    StartCoroutine ( m_DownloadPlayFab.Download ( "helloWorld" ) );
}

void OnDownloadSuccess ( GetUserDataResult result )
{
    Debug.Log ( "Download Successful" );

    // Load the data.
    string helloWorld = m_DownloadPlayFab.Load<string> ( defaultValue );
}

void OnDownloadFailure ( PlayFabError error )
{
    Debug.LogError ( "Download Failed" );
    Debug.LogError ( error.GenerateErrorReport () );
}