Advertisement
thieumao

PlayFab - Set Name Display

Jun 27th, 2016
314
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.40 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("iduser");
  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.                     setDisplayName("Name Display In PlayFab");
  55.                 }
  56.                 else
  57.                 {
  58.                     Debug.Log("(existing account)");
  59.                 }
  60.             },
  61.             (error) =>
  62.             {
  63.                 Debug.Log("Error logging in player with custom ID:");
  64.                 Debug.Log(error.ErrorMessage);
  65.             }
  66.         );
  67.     }
  68.  
  69.     private void setDisplayName(String displayName)
  70.     {
  71.         UpdateUserTitleDisplayNameRequest request = new UpdateUserTitleDisplayNameRequest()
  72.         {
  73.             DisplayName = displayName
  74.         };
  75.  
  76.         PlayFabClientAPI.UpdateUserTitleDisplayName(
  77.             request,
  78.             (result) =>
  79.             {
  80.                 print("Current name in playfab: " + result.DisplayName);
  81.             },
  82.             (error) =>
  83.             {
  84.                 Debug.Log(error.ErrorMessage);
  85.             }
  86.         );
  87.     }
  88.  
  89. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement