Skip to content

Template Class

Jiufen edited this page Mar 9, 2021 · 1 revision

🏗Template Class🏗

For the user Login PlayFab recommends to use this template to start creating the login of your app:

using Unity.Entities;

using PlayFab;
using PlayFab.ClientModels;
using UnityEngine;

public class PlayFabLogin : MonoBehaviour
{
    public void Start()
    {
        //Note: Setting title Id here can be skipped if you have set the value in Editor Extensions already.
        if (string.IsNullOrEmpty(PlayFabSettings.TitleId)){
            PlayFabSettings.TitleId = "144"; // Here goes your own titleId from PlayFab Game Manager
        }
        var request = new LoginWithCustomIDRequest { CustomId = "GettingStartedGuide", CreateAccount = true};
        PlayFabClientAPI.LoginWithCustomID(request, OnLoginPlayFabSuccess, OnLoginPlayFabFailure);
    }

    private void OnLoginPlayFabSuccess(LoginResult result)
    {
        Debug.Log("Congratulations, you made your first successful API call!");
    }

    private void OnLoginPlayFabFailure(PlayFabError error)
    {
        Debug.LogWarning("Something went wrong with your first API call.  :(");
        Debug.LogError("Here's some debug information:");
        Debug.LogError(error.GenerateErrorReport());
    }
}

In the next section of the wiki we are going to explain how to modify this code to add a real authentication service.

Clone this wiki locally