You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
PlumberUltimateAds/Assets/Scripts/Dev/PlayFab/PlayFabInit.cs

79 lines
2.4 KiB
C#

1 month ago
using System.Collections;
using System.Collections.Generic;
using PlayFab;
using PlayFab.ClientModels;
using UnityEngine;
using UnityEngine.SceneManagement;
1 month ago
public class PlayFabInit : MonoBehaviour
{
public string playFabTitleId = "7D3B9"; // Replace with your PlayFab Title ID
1 month ago
void Start()
{
1 month ago
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
// }
// }
1 month ago
};
PlayFabClientAPI.LoginWithCustomID(request, OnLoginSuccess, OnLoginFailure);
1 month ago
}
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");
SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex + 1);
PlayFabManager.Instance.myProfile = obj.PlayerProfile;
1 month ago
}
private void OnLoginFailure(PlayFabError error)
{
Debug.LogError("Login failed: " + error.GenerateErrorReport());
}
}