Advertisement
thieumao

PlayFab - Login

Jun 27th, 2016
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.81 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Collections;
  4. using System.Collections.Generic;
  5. using UnityEngine;
  6. using PlayFab;
  7. using PlayFab.ClientModels;
  8.  
  9. public class PlayFabManager : MonoBehaviour
  10. {
  11.     // PlayFab ID Default --> change it
  12.     // Petvenger Dev >> androidvn.com@gmail.com /1q2w3e4r5t@123
  13.     public string PlayfabID = "FD55";
  14.     public string CustomAccountID = "";
  15.     // Time
  16.     public int TimeStartCheckToken = 30;
  17.     public int TimePeriodCheckToken = 30;
  18.  
  19.     public static PlayFabManager Instance;
  20.  
  21.     private bool isDoneDownTitleData = false;
  22.     private bool isDoneDownDataUser = false;
  23.  
  24.     void Awake()
  25.     {
  26.         DontDestroyOnLoad(this);
  27.         Instance = this;
  28.         PlayFabSettings.TitleId = PlayfabID;
  29.  
  30.         Login("thieumao");
  31.     }
  32.  
  33.     [ContextMenu("Login PlayFab")]
  34.     public void Login(string CustomAccountLogin)
  35.     {
  36.         print("Login with " + CustomAccountLogin);
  37.  
  38.         LoginWithCustomIDRequest request = new LoginWithCustomIDRequest()
  39.         {
  40.             TitleId = PlayfabID,
  41.             CreateAccount = true,
  42.             CustomId = CustomAccountLogin
  43.         };
  44.  
  45.         PlayFabClientAPI.LoginWithCustomID(
  46.             request,
  47.             (result) =>
  48.             {
  49.                 CustomAccountID = result.PlayFabId;
  50.                 Debug.Log("Got PlayFabID: " + CustomAccountLogin);
  51.                 if (result.NewlyCreated)
  52.                 {
  53.                     Debug.Log("(new account)");
  54.                 }
  55.                 else
  56.                 {
  57.                     Debug.Log("(existing account)");
  58.                 }
  59.             },
  60.             (error) =>
  61.             {
  62.                 Debug.Log("Error logging in player with custom ID:");
  63.                 Debug.Log(error.ErrorMessage);
  64.             }
  65.         );
  66.     }
  67.  
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement