SHARE
TWEET

Untitled

a guest Aug 28th, 2018 70 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.Networking;
  5. using PlayFab;
  6. using PlayFab.ClientModels;
  7. using UnityEngine.UI;
  8.  
  9. public class PlayfabClient : MonoBehaviour
  10. {
  11.  
  12.     public string titleId;
  13.     public string buildVersion;
  14.  
  15.     public NetworkManager netManager;
  16.     public GameObject loginForm;
  17.     public GameObject findGameUI;
  18.  
  19.     public InputField loginUsername;
  20.     public InputField loginPassword;
  21.  
  22.     public InputField registerUsername;
  23.     public InputField registerPassword;
  24.     public InputField registerEmail;
  25.  
  26.     public GameObject errorBox;
  27.     public Text errorText;
  28.  
  29.     // Use this for initialization
  30.     void Start()
  31.     {
  32.         PlayFabSettings.TitleId = titleId;
  33.     }
  34.  
  35.     public void OnPressLogin()
  36.     {
  37.         var req = new LoginWithPlayFabRequest() { Username = loginUsername.text, Password = loginPassword.text };
  38.         PlayFabClientAPI.LoginWithPlayFab(req, OnLoginSuccess, OnError);
  39.     }
  40.  
  41.     public void OnPressRegister()
  42.     {
  43.         var req = new RegisterPlayFabUserRequest()
  44.         {
  45.             Username = registerUsername.text,
  46.             Password = registerPassword.text,
  47.             Email = registerEmail.text,
  48.             DisplayName = registerUsername.text
  49.         };
  50.         PlayFabClientAPI.RegisterPlayFabUser(req, OnRegisterSuccess, OnError);
  51.     }
  52.  
  53.     void OnLoginSuccess(LoginResult result)
  54.     {
  55.         loginForm.SetActive(false);
  56.         findGameUI.SetActive(true);
  57.     }
  58.  
  59.     void OnRegisterSuccess(RegisterPlayFabUserResult result)
  60.     {
  61.         errorBox.SetActive(true);
  62.         errorText.text = "Success!";
  63.     }
  64.  
  65.     void OnError(PlayFabError error)
  66.     {
  67.         errorBox.SetActive(true);
  68.         errorText.text = error.ErrorMessage;
  69.     }
  70.  
  71.     public void FindGame()
  72.     {
  73.         /*
  74.         var req = new MatchmakeRequest() { BuildVersion = buildVersion, Region = Region.EUWest, GameMode = "Basic", StartNewIfNoneFound = true };
  75.         PlayFabClientAPI.Matchmake(req, OnFoundGame, OnError);
  76.         */
  77.  
  78.         var req = new StartGameRequest() { BuildVersion = buildVersion, GameMode = "Basic", Region = Region.EUWest };
  79.         PlayFabClientAPI.StartGame(req, result =>
  80.         {
  81.             netManager.networkAddress = result.ServerIPV4Address;
  82.             netManager.networkPort = (int)result.ServerPort;
  83.             netManager.StartClient();
  84.         }, OnError);
  85.     }
  86.  
  87.     void OnFoundGame(MatchmakeResult result)
  88.     {
  89.         netManager.networkAddress = result.ServerIPV4Address;
  90.         netManager.networkPort = (int)result.ServerPort;
  91.         netManager.StartClient();
  92.     }
  93. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top