Advertisement
Guest User

Untitled

a guest
Jun 15th, 2016
230
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.94 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3. using PlayFab;
  4. using PlayFab.ClientModels;
  5. using Photon;
  6. using UnityEngine.UI;
  7. using System;
  8. using System.Collections.Generic;
  9.  
  10. public class PlayFabManager : Photon.MonoBehaviour {
  11.  
  12.     private string PlayFabId;
  13.  
  14.     public string newsToLoad;
  15.  
  16.     public GameObject UpdateContainer;
  17.     public GameObject UpdateText;
  18.     public GameObject RegisterContainer;
  19.     public GameObject LoginContainer;
  20.  
  21.     public InputField RegisterPasswordInput;
  22.     public InputField RegisterUsernameInput;
  23.     public InputField RegsiterEmailInput;
  24.  
  25.  
  26.     public InputField LoginUsernameInput;
  27.     public InputField LoginPasswordInput;
  28.  
  29.     private List<TitleNewsItem> news;
  30.     private bool newsLoaded = false;
  31.     private bool showNews = false;
  32.  
  33.     private string sessionTicket;
  34.  
  35.  
  36.  
  37.     // Use this for initialization
  38.     void Start () {
  39.  
  40.         PlayFabSettings.TitleId = "6FA2";
  41.         PhotonNetwork.ConnectUsingSettings("PhotonServerSettings");
  42.  
  43.        
  44.  
  45.     }
  46.    
  47.     // Update is called once per frame
  48.     void Update () {
  49.  
  50.  
  51.         if (sessionTicket != null)
  52.         {
  53.             /* Not sure why this doesnt work it intantiates way more things than exists
  54.             if (!newsLoaded)
  55.             {
  56.                 GetTitleNewsRequest request = new GetTitleNewsRequest();
  57.                 Debug.Log(newsToLoad);
  58.                 PlayFabClientAPI.GetTitleNews(request, GetNewsUpdates, OnPlayFabError);
  59.  
  60.             }*/
  61.         }
  62.     }
  63.  
  64.     void OnLoginSuccessful()
  65.     {
  66.  
  67.  
  68.     }
  69.  
  70.     private void OnPlayFabError(PlayFabError error)
  71.     {
  72.         Debug.Log("Got an error: " + error.ErrorMessage);
  73.         Debug.Log("Code: " + error.ErrorDetails);
  74.     }
  75.  
  76.     public void Login(string titleId)
  77.     {
  78.         LoginWithPlayFabRequest request = new LoginWithPlayFabRequest()
  79.         {
  80.             TitleId = "6FA2",
  81.             Username = LoginUsernameInput.text,
  82.             Password = LoginPasswordInput.text
  83.         };
  84.         PlayFabClientAPI.LoginWithPlayFab(request, (result) =>
  85.         {
  86.             LoginContainer.SetActive(false);
  87.             RegisterContainer.SetActive(false);
  88.             Debug.Log(result.SessionTicket);
  89.             sessionTicket = result.SessionTicket;
  90.  
  91.         },
  92.         (error) =>
  93.         {
  94.             Debug.Log("Error logging in player with playfab ID:");
  95.             Debug.Log(error.ErrorMessage);
  96.             Debug.Log(error.HttpCode);
  97.         });
  98.        
  99.     }
  100.  
  101.     public void CreateAccount(string titleId)
  102.     {
  103.         RegisterPlayFabUserRequest request = new RegisterPlayFabUserRequest()
  104.         {
  105.             TitleId = titleId,
  106.             RequireBothUsernameAndEmail = true,
  107.             Username = RegisterUsernameInput.text,
  108.             DisplayName = RegisterUsernameInput.text,
  109.             Password = RegisterPasswordInput.text,
  110.             Email = RegsiterEmailInput.text          
  111.         };
  112.         Debug.Log(RegisterUsernameInput.text);
  113.         Debug.Log(RegisterPasswordInput.text);
  114.         Debug.Log(RegsiterEmailInput.text);
  115.  
  116.         PlayFabClientAPI.RegisterPlayFabUser(request, (result) =>
  117.         {
  118.             PlayFabId = result.PlayFabId;
  119.             Debug.Log(result.Username);
  120.            
  121.            
  122.         },
  123.         (error) =>
  124.         {
  125.             Debug.Log("Error logging in player with playfab ID:");
  126.             Debug.Log(error.ErrorMessage);
  127.             Debug.Log(error.HttpCode);
  128.  
  129.         });
  130.     }
  131.  
  132.     private void GetNewsUpdates(GetTitleNewsResult result)
  133.     {
  134.         news = result.News;
  135.         newsLoaded = true;
  136.  
  137.         for (int i = 0; i < news.Count; i++)
  138.         {
  139.             GameObject updateText = Instantiate(UpdateText,Vector3.zero, Quaternion.identity) as GameObject;
  140.             updateText.transform.SetParent(UpdateContainer.transform);
  141.             updateText.GetComponent<Text>().text = news[i].Body + news[i].Timestamp;
  142.                
  143.         }
  144.  
  145.        
  146.        
  147.     }
  148.  
  149.  
  150. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement