Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- using PlayFab;
- using PlayFab.ClientModels;
- using Photon;
- using UnityEngine.UI;
- using System;
- using System.Collections.Generic;
- public class PlayFabManager : Photon.MonoBehaviour {
- private string PlayFabId;
- public string newsToLoad;
- public GameObject UpdateContainer;
- public GameObject UpdateText;
- public GameObject RegisterContainer;
- public GameObject LoginContainer;
- public InputField RegisterPasswordInput;
- public InputField RegisterUsernameInput;
- public InputField RegsiterEmailInput;
- public InputField LoginUsernameInput;
- public InputField LoginPasswordInput;
- private List<TitleNewsItem> news;
- private bool newsLoaded = false;
- private bool showNews = false;
- private string sessionTicket;
- // Use this for initialization
- void Start () {
- PlayFabSettings.TitleId = "6FA2";
- PhotonNetwork.ConnectUsingSettings("PhotonServerSettings");
- }
- // Update is called once per frame
- void Update () {
- if (sessionTicket != null)
- {
- /* Not sure why this doesnt work it intantiates way more things than exists
- if (!newsLoaded)
- {
- GetTitleNewsRequest request = new GetTitleNewsRequest();
- Debug.Log(newsToLoad);
- PlayFabClientAPI.GetTitleNews(request, GetNewsUpdates, OnPlayFabError);
- }*/
- }
- }
- void OnLoginSuccessful()
- {
- }
- private void OnPlayFabError(PlayFabError error)
- {
- Debug.Log("Got an error: " + error.ErrorMessage);
- Debug.Log("Code: " + error.ErrorDetails);
- }
- public void Login(string titleId)
- {
- LoginWithPlayFabRequest request = new LoginWithPlayFabRequest()
- {
- TitleId = "6FA2",
- Username = LoginUsernameInput.text,
- Password = LoginPasswordInput.text
- };
- PlayFabClientAPI.LoginWithPlayFab(request, (result) =>
- {
- LoginContainer.SetActive(false);
- RegisterContainer.SetActive(false);
- Debug.Log(result.SessionTicket);
- sessionTicket = result.SessionTicket;
- },
- (error) =>
- {
- Debug.Log("Error logging in player with playfab ID:");
- Debug.Log(error.ErrorMessage);
- Debug.Log(error.HttpCode);
- });
- }
- public void CreateAccount(string titleId)
- {
- RegisterPlayFabUserRequest request = new RegisterPlayFabUserRequest()
- {
- TitleId = titleId,
- RequireBothUsernameAndEmail = true,
- Username = RegisterUsernameInput.text,
- DisplayName = RegisterUsernameInput.text,
- Password = RegisterPasswordInput.text,
- Email = RegsiterEmailInput.text
- };
- Debug.Log(RegisterUsernameInput.text);
- Debug.Log(RegisterPasswordInput.text);
- Debug.Log(RegsiterEmailInput.text);
- PlayFabClientAPI.RegisterPlayFabUser(request, (result) =>
- {
- PlayFabId = result.PlayFabId;
- Debug.Log(result.Username);
- },
- (error) =>
- {
- Debug.Log("Error logging in player with playfab ID:");
- Debug.Log(error.ErrorMessage);
- Debug.Log(error.HttpCode);
- });
- }
- private void GetNewsUpdates(GetTitleNewsResult result)
- {
- news = result.News;
- newsLoaded = true;
- for (int i = 0; i < news.Count; i++)
- {
- GameObject updateText = Instantiate(UpdateText,Vector3.zero, Quaternion.identity) as GameObject;
- updateText.transform.SetParent(UpdateContainer.transform);
- updateText.GetComponent<Text>().text = news[i].Body + news[i].Timestamp;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement