using System.Collections; using System.Collections.Generic; using PlayFab; using PlayFab.ClientModels; using UnityEngine; using UnityEngine.SceneManagement; public class PlayFabInit : MonoBehaviour { public string playFabTitleId = "7D3B9"; // Replace with your PlayFab Title ID void Start() { if (string.IsNullOrEmpty(PlayFabSettings.TitleId)) { PlayFabSettings.TitleId = playFabTitleId; } Login(); } void Login() { var request = new LoginWithCustomIDRequest { CustomId = SystemInfo.deviceUniqueIdentifier, CreateAccount = true, // InfoRequestParameters = new GetPlayerCombinedInfoRequestParams // { // GetPlayerProfile = true, // This will include player profile data in the login response // ProfileConstraints = new PlayerProfileViewConstraints // { // ShowDisplayName = true, // ShowAvatarUrl = true, // ShowCreated = true // } // } }; PlayFabClientAPI.LoginWithCustomID(request, OnLoginSuccess, OnLoginFailure); } private void OnLoginSuccess(LoginResult result) { Debug.Log("Login successful!"); GetPlayerProfile(); } public void GetPlayerProfile() { var request = new GetPlayerProfileRequest { PlayFabId = PlayFabSettings.staticPlayer.PlayFabId, ProfileConstraints = new PlayerProfileViewConstraints { ShowDisplayName = true, // Allowed by your title settings // Do not request AvatarUrl or other fields, since they are disallowed } }; PlayFabClientAPI.GetPlayerProfile(request, OnGetProfileSuccess, OnGetProfileFailure); } private void OnGetProfileFailure(PlayFabError obj) { Debug.LogError("Couldn't Fetch Player Profile " + obj.GenerateErrorReport()); } private void OnGetProfileSuccess(GetPlayerProfileResult obj) { Debug.Log("Player profile fetching successful"); PlayFabManager.Instance.myProfile = obj.PlayerProfile; } private void OnLoginFailure(PlayFabError error) { Debug.LogError("Login failed: " + error.GenerateErrorReport()); } }