Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.Networking;
- using PlayFab;
- using PlayFab.ClientModels;
- using UnityEngine.UI;
- public class PlayfabClient : MonoBehaviour
- {
- public string titleId;
- public string buildVersion;
- public NetworkManager netManager;
- public GameObject loginForm;
- public GameObject findGameUI;
- public InputField loginUsername;
- public InputField loginPassword;
- public InputField registerUsername;
- public InputField registerPassword;
- public InputField registerEmail;
- public GameObject errorBox;
- public Text errorText;
- // Use this for initialization
- void Start()
- {
- PlayFabSettings.TitleId = titleId;
- }
- public void OnPressLogin()
- {
- var req = new LoginWithPlayFabRequest() { Username = loginUsername.text, Password = loginPassword.text };
- PlayFabClientAPI.LoginWithPlayFab(req, OnLoginSuccess, OnError);
- }
- public void OnPressRegister()
- {
- var req = new RegisterPlayFabUserRequest()
- {
- Username = registerUsername.text,
- Password = registerPassword.text,
- Email = registerEmail.text,
- DisplayName = registerUsername.text
- };
- PlayFabClientAPI.RegisterPlayFabUser(req, OnRegisterSuccess, OnError);
- }
- void OnLoginSuccess(LoginResult result)
- {
- loginForm.SetActive(false);
- findGameUI.SetActive(true);
- }
- void OnRegisterSuccess(RegisterPlayFabUserResult result)
- {
- errorBox.SetActive(true);
- errorText.text = "Success!";
- }
- void OnError(PlayFabError error)
- {
- errorBox.SetActive(true);
- errorText.text = error.ErrorMessage;
- }
- public void FindGame()
- {
- /*
- var req = new MatchmakeRequest() { BuildVersion = buildVersion, Region = Region.EUWest, GameMode = "Basic", StartNewIfNoneFound = true };
- PlayFabClientAPI.Matchmake(req, OnFoundGame, OnError);
- */
- var req = new StartGameRequest() { BuildVersion = buildVersion, GameMode = "Basic", Region = Region.EUWest };
- PlayFabClientAPI.StartGame(req, result =>
- {
- netManager.networkAddress = result.ServerIPV4Address;
- netManager.networkPort = (int)result.ServerPort;
- netManager.StartClient();
- }, OnError);
- }
- void OnFoundGame(MatchmakeResult result)
- {
- netManager.networkAddress = result.ServerIPV4Address;
- netManager.networkPort = (int)result.ServerPort;
- netManager.StartClient();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement