PlayFabController.cs<\/h3>\n\n\n\nusing PlayFab;\nusing PlayFab.ClientModels;\nusing UnityEngine;\nusing PlayFab.DataModels;\nusing PlayFab.ProfilesModels;\nusing System.Collections.Generic;\nusing PlayFab.Json;\n\npublic class PlayFabController : MonoBehaviour\n{\n public static PlayFabController PFC;\n\n private string userEmail;\n private string userPassword;\n private string username;\n public GameObject loginPanel;\n public GameObject addLoginPanel;\n public GameObject recoverButton;\n\n private void OnEnable()\n {\n if(PlayFabController.PFC == null)\n {\n PlayFabController.PFC = this;\n }\n else\n {\n if(PlayFabController.PFC != this)\n {\n Destroy(this.gameObject);\n }\n }\n DontDestroyOnLoad(this.gameObject);\n }\n\n public void Start()\n {\n \/\/Note: Setting title Id here can be skipped if you have set the value in Editor Extensions already.\n if (string.IsNullOrEmpty(PlayFabSettings.TitleId))\n {\n PlayFabSettings.TitleId = \"8741\"; \/\/ Please change this value to your own titleId from PlayFab Game Manager\n }\n \/\/PlayerPrefs.DeleteAll();\n \/\/var request = new LoginWithCustomIDRequest { CustomId = \"GettingStartedGuide\", CreateAccount = true };\n \/\/PlayFabClientAPI.LoginWithCustomID(request, OnLoginSuccess, OnLoginFailure);\n if (PlayerPrefs.HasKey(\"EMAIL\"))\n {\n userEmail = PlayerPrefs.GetString(\"EMAIL\");\n userPassword = PlayerPrefs.GetString(\"PASSWORD\");\n var request = new LoginWithEmailAddressRequest { Email = userEmail, Password = userPassword };\n PlayFabClientAPI.LoginWithEmailAddress(request, OnLoginSuccess, OnLoginFailure);\n }\n else\n {\n#if UNITY_ANDROID\n var requestAndroid = new LoginWithAndroidDeviceIDRequest { AndroidDeviceId = ReturnMobileID(), CreateAccount = true };\n PlayFabClientAPI.LoginWithAndroidDeviceID(requestAndroid, OnLoginMobileSuccess, OnLoginMobileFailure);\n#endif\n#if UNITY_IOS\n var requestIOS = new LoginWithIOSDeviceIDRequest { DeviceId = ReturnMobileID(), CreateAccount = true };\n PlayFabClientAPI.LoginWithIOSDeviceID(requestIOS, OnLoginMobileSuccess, OnLoginMobileFailure);\n#endif\n }\n\n\n }\n\n #region Login\n private void OnLoginSuccess(LoginResult result)\n {\n Debug.Log(\"Congratulations, you made your first successful API call!\");\n PlayerPrefs.SetString(\"EMAIL\", userEmail);\n PlayerPrefs.SetString(\"PASSWORD\", userPassword);\n loginPanel.SetActive(false);\n recoverButton.SetActive(false);\n GetStats();\n \/\/StartCloudHelloWorld();\n\n }\n\n private void OnLoginMobileSuccess(LoginResult result)\n {\n Debug.Log(\"Congratulations, you made your first successful API call!\");\n GetStats();\n loginPanel.SetActive(false);\n }\n\n private void OnRegisterSuccess(RegisterPlayFabUserResult result)\n {\n Debug.Log(\"Congratulations, you made your first successful API call!\");\n PlayerPrefs.SetString(\"EMAIL\", userEmail);\n PlayerPrefs.SetString(\"PASSWORD\", userPassword);\n\n PlayFabClientAPI.UpdateUserTitleDisplayName(new UpdateUserTitleDisplayNameRequest { DisplayName = username }, OnDisplayName, OnLoginMobileFailure);\n GetStats();\n loginPanel.SetActive(false);\n }\n\n void OnDisplayName(UpdateUserTitleDisplayNameResult result)\n {\n Debug.Log(result.DisplayName + \" is your new display name\");\n }\n\n private void OnLoginFailure(PlayFabError error)\n {\n var registerRequest = new RegisterPlayFabUserRequest { Email = userEmail, Password = userPassword, Username = username };\n PlayFabClientAPI.RegisterPlayFabUser(registerRequest, OnRegisterSuccess, OnRegisterFailure);\n }\n\n private void OnLoginMobileFailure(PlayFabError error)\n {\n Debug.Log(error.GenerateErrorReport());\n }\n\n private void OnRegisterFailure(PlayFabError error)\n {\n Debug.LogError(error.GenerateErrorReport());\n }\n\n\n public void GetUserEmail(string emailIn)\n {\n userEmail = emailIn;\n }\n\n public void GetUserPassword(string passwordIn)\n {\n userPassword = passwordIn;\n }\n\n public void GetUsername(string usernameIn)\n {\n username = usernameIn;\n }\n\n public void OnClickLogin()\n {\n var request = new LoginWithEmailAddressRequest { Email = userEmail, Password = userPassword };\n PlayFabClientAPI.LoginWithEmailAddress(request, OnLoginSuccess, OnLoginFailure);\n }\n\n public static string ReturnMobileID()\n {\n string deviceID = SystemInfo.deviceUniqueIdentifier;\n return deviceID;\n }\n\n public void OpenAddLogin()\n {\n addLoginPanel.SetActive(true);\n }\n\n public void OnClickAddLogin()\n {\n var addLoginRequest = new AddUsernamePasswordRequest { Email = userEmail, Password = userPassword, Username = username };\n PlayFabClientAPI.AddUsernamePassword(addLoginRequest, OnAddLoginSuccess, OnRegisterFailure);\n }\n\n private void OnAddLoginSuccess(AddUsernamePasswordResult result)\n {\n Debug.Log(\"Congratulations, you made your first successful API call!\");\n GetStats();\n PlayerPrefs.SetString(\"EMAIL\", userEmail);\n PlayerPrefs.SetString(\"PASSWORD\", userPassword);\n addLoginPanel.SetActive(false);\n }\n #endregion Login\n\n public int playerLevel;\n public int gameLevel;\n\n public int playerHealth;\n public int playerDamage;\n\n public int playerHighScore;\n\n #region PlayerStats\n\n public void SetStats()\n {\n PlayFabClientAPI.UpdatePlayerStatistics(new UpdatePlayerStatisticsRequest\n {\n \/\/ request.Statistics is a list, so multiple StatisticUpdate objects can be defined if required.\n Statistics = new List<StatisticUpdate> {\n new StatisticUpdate { StatisticName = \"PlayerLevel\", Value = playerLevel },\n new StatisticUpdate { StatisticName = \"GameLevel\", Value = gameLevel },\n new StatisticUpdate { StatisticName = \"PlayerHealth\", Value = playerHealth },\n new StatisticUpdate { StatisticName = \"PlayerDamage\", Value = playerDamage },\n new StatisticUpdate { StatisticName = \"PlayerHighScore\", Value = playerHighScore },\n \n }\n },\n result => { Debug.Log(\"User statistics updated\"); },\n error => { Debug.LogError(error.GenerateErrorReport()); });\n }\n\n void GetStats()\n {\n PlayFabClientAPI.GetPlayerStatistics(\n new GetPlayerStatisticsRequest(),\n OnGetStats,\n error => Debug.LogError(error.GenerateErrorReport())\n );\n }\n\n void OnGetStats(GetPlayerStatisticsResult result)\n {\n Debug.Log(\"Received the following Statistics:\");\n foreach (var eachStat in result.Statistics)\n {\n Debug.Log(\"Statistic (\" + eachStat.StatisticName + \"): \" + eachStat.Value);\n switch(eachStat.StatisticName)\n {\n case \"PlayerLevel\":\n playerLevel = eachStat.Value;\n break;\n case \"GameLevel\":\n gameLevel = eachStat.Value;\n break;\n case \"PlayerHealth\":\n playerHealth = eachStat.Value;\n break;\n case \"PlayerDamage\":\n playerDamage = eachStat.Value;\n break;\n case \"PlayerHighScore\":\n playerHighScore = eachStat.Value;\n break;\n }\n }\n }\n\n \/\/ Build the request object and access the API\n public void StartCloudUpdatePlayerStats()\n {\n PlayFabClientAPI.ExecuteCloudScript(new ExecuteCloudScriptRequest()\n {\n FunctionName = \"UpdatePlayerStats\", \/\/ Arbitrary function name (must exist in your uploaded cloud.js file)\n FunctionParameter = new { Level = playerLevel, highScore =playerHighScore, apple = 0 }, \/\/ The parameter provided to your function\n GeneratePlayStreamEvent = true, \/\/ Optional - Shows this event in PlayStream\n }, OnCloudUpdateStats, OnErrorShared);\n }\n \/\/ OnCloudHelloWorld defined in the next code block\n\n private static void OnCloudUpdateStats(ExecuteCloudScriptResult result)\n {\n \/\/ Cloud Script returns arbitrary results, so you have to evaluate them one step and one parameter at a time\n Debug.Log(JsonWrapper.SerializeObject(result.FunctionResult));\n JsonObject jsonResult = (JsonObject)result.FunctionResult;\n object messageValue;\n jsonResult.TryGetValue(\"messageValue\", out messageValue); \/\/ note how \"messageValue\" directly corresponds to the JSON values set in Cloud Script\n Debug.Log((string)messageValue);\n }\n\n private static void OnErrorShared(PlayFabError error)\n {\n Debug.Log(error.GenerateErrorReport());\n }\n\n #endregion PlayerStats\n}\n<\/pre>\n\n\n\nusing Photon.Chat;\nusing Photon.Pun;\nusing System.Collections;\nusing System.Collections.Generic;\nusing UnityEngine;\nusing UnityEngine.UI;\n\npublic class PhotonChatManager : MonoBehaviour, IChatClientListener\n{\n #region Setup\n\n [SerializeField] GameObject joinChatButton;\n ChatClient chatClient;\n bool isConnected;\n [SerializeField] string username;\n\n public void UsernameOnValueChange(string valueIn)\n {\n username = valueIn;\n }\n\n public void ChatConnectOnClick()\n {\n isConnected = true;\n chatClient = new ChatClient(this);\n \/\/chatClient.ChatRegion = \"US\";\n chatClient.Connect(PhotonNetwork.PhotonServerSettings.AppSettings.AppIdChat, PhotonNetwork.AppVersion, new AuthenticationValues(username));\n Debug.Log(\"Connenting\");\n }\n\n #endregion Setup\n\n #region General\n\n [SerializeField] GameObject chatPanel;\n string privateReceiver = \"\";\n string currentChat;\n [SerializeField] InputField chatField;\n [SerializeField] Text chatDisplay;\n\n \/\/ Start is called before the first frame update\n void Start()\n {\n\n }\n\n \/\/ Update is called once per frame\n void Update()\n {\n if (isConnected)\n {\n chatClient.Service();\n }\n\n if (chatField.text != \"\" && Input.GetKey(KeyCode.Return))\n {\n SubmitPublicChatOnClick();\n SubmitPrivateChatOnClick();\n }\n }\n\n #endregion General\n\n #region PublicChat\n\n public void SubmitPublicChatOnClick()\n {\n if (privateReceiver == \"\")\n {\n chatClient.PublishMessage(\"RegionChannel\", currentChat);\n chatField.text = \"\";\n currentChat = \"\";\n }\n }\n\n public void TypeChatOnValueChange(string valueIn)\n {\n currentChat = valueIn;\n }\n\n #endregion PublicChat\n\n #region PrivateChat\n\n public void ReceiverOnValueChange(string valueIn)\n {\n privateReceiver = valueIn;\n }\n\n public void SubmitPrivateChatOnClick()\n {\n if (privateReceiver != \"\")\n {\n chatClient.SendPrivateMessage(privateReceiver, currentChat);\n chatField.text = \"\";\n currentChat = \"\";\n }\n }\n\n #endregion PrivateChat\n\n #region Callbacks\n\n public void DebugReturn(DebugLevel level, string message)\n {\n \/\/throw new System.NotImplementedException();\n }\n\n public void OnChatStateChange(ChatState state)\n {\n if(state == ChatState.Uninitialized)\n {\n isConnected = false;\n joinChatButton.SetActive(true);\n chatPanel.SetActive(false);\n }\n }\n\n public void OnConnected()\n {\n Debug.Log(\"Connected\");\n joinChatButton.SetActive(false);\n chatClient.Subscribe(new string[] { \"RegionChannel\" });\n }\n\n public void OnDisconnected()\n {\n isConnected = false;\n joinChatButton.SetActive(true);\n chatPanel.SetActive(false);\n }\n\n public void OnGetMessages(string channelName, string[] senders, object[] messages)\n {\n string msgs = \"\";\n for (int i = 0; i < senders.Length; i++)\n {\n msgs = string.Format(\"{0}: {1}\", senders[i], messages[i]);\n\n chatDisplay.text += \"\\n\" + msgs;\n\n Debug.Log(msgs);\n }\n\n }\n\n public void OnPrivateMessage(string sender, object message, string channelName)\n {\n string msgs = \"\";\n\n msgs = string.Format(\"(Private) {0}: {1}\", sender, message);\n\n chatDisplay.text += \"\\n \" + msgs;\n\n Debug.Log(msgs);\n \n }\n\n public void OnStatusUpdate(string user, int status, bool gotMessage, object message)\n {\n throw new System.NotImplementedException();\n }\n\n public void OnSubscribed(string[] channels, bool[] results)\n {\n chatPanel.SetActive(true);\n }\n\n public void OnUnsubscribed(string[] channels)\n {\n throw new System.NotImplementedException();\n }\n\n public void OnUserSubscribed(string channel, string user)\n {\n throw new System.NotImplementedException();\n }\n\n public void OnUserUnsubscribed(string channel, string user)\n {\n throw new System.NotImplementedException();\n }\n\n #endregion Callbacks\n}<\/pre>\n\n\n\n