|
|
|
@ -64,34 +64,46 @@ public class GoogleSignInManager : MonoBehaviour
|
|
|
|
|
|
|
|
|
|
GoogleSignInUser user = task.Result;
|
|
|
|
|
string authCode = user.AuthCode;
|
|
|
|
|
PlayerPrefs.SetString("GoogleAuthCode", authCode);
|
|
|
|
|
PlayerPrefsKeys.RegisterKey("GoogleAuthCode");
|
|
|
|
|
PlayerPrefs.Save();
|
|
|
|
|
SafePlayerPrefs.SetString("GoogleAuthCode", authCode);
|
|
|
|
|
//PlayerPrefsKeys.RegisterKey("GoogleAuthCode");
|
|
|
|
|
//PlayerPrefs.Save();
|
|
|
|
|
|
|
|
|
|
LoginToPlayFab(authCode);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void SignInSilently()
|
|
|
|
|
{
|
|
|
|
|
if (PlayerPrefs.HasKey("GoogleAuthCode"))
|
|
|
|
|
Debug.Log("Attempting Google Silent Sign-In...");
|
|
|
|
|
|
|
|
|
|
GoogleSignIn.DefaultInstance.SignInSilently().ContinueWith(task =>
|
|
|
|
|
{
|
|
|
|
|
string authCode = PlayerPrefs.GetString("GoogleAuthCode");
|
|
|
|
|
if (task.IsFaulted || task.IsCanceled)
|
|
|
|
|
{
|
|
|
|
|
Debug.LogWarning("Silent Sign-In failed, falling back to interactive sign-in.");
|
|
|
|
|
googleSignInButton.gameObject.SetActive(true);
|
|
|
|
|
googleSignInButton.interactable = true;
|
|
|
|
|
googleSignInButton.onClick.RemoveAllListeners();
|
|
|
|
|
googleSignInButton.onClick.AddListener(SignInWithGoogle);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
GoogleSignInUser user = task.Result;
|
|
|
|
|
string authCode = user.AuthCode;
|
|
|
|
|
|
|
|
|
|
// Store it if needed for debugging — not for reuse
|
|
|
|
|
SafePlayerPrefs.SetString("GoogleAuthCode", authCode);
|
|
|
|
|
|
|
|
|
|
LoginToPlayFab(authCode);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Debug.LogWarning("No Google AuthCode found for silent sign-in.");
|
|
|
|
|
googleSignInButton.gameObject.SetActive(true);
|
|
|
|
|
googleSignInButton.onClick.RemoveAllListeners();
|
|
|
|
|
googleSignInButton.onClick.AddListener(SignInWithGoogle);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void LoginToPlayFab(string authCode)
|
|
|
|
|
{
|
|
|
|
|
PlayFabSettings.staticSettings.TitleId = "1879F5";
|
|
|
|
|
var request = new LoginWithGoogleAccountRequest
|
|
|
|
|
{
|
|
|
|
|
TitleId = PlayFabSettings.TitleId,
|
|
|
|
|
TitleId = "1879F5",
|
|
|
|
|
ServerAuthCode = authCode,
|
|
|
|
|
CreateAccount = true
|
|
|
|
|
};
|
|
|
|
@ -103,9 +115,9 @@ public class GoogleSignInManager : MonoBehaviour
|
|
|
|
|
{
|
|
|
|
|
Debug.Log("✅ PlayFab Login Success! PlayFab ID: " + result.PlayFabId);
|
|
|
|
|
|
|
|
|
|
PlayerPrefs.SetString("PlayFabID", result.PlayFabId);
|
|
|
|
|
PlayerPrefsKeys.RegisterKey("PlayFabID");
|
|
|
|
|
PlayerPrefs.Save();
|
|
|
|
|
SafePlayerPrefs.SetString("PlayFabID", result.PlayFabId);
|
|
|
|
|
//PlayerPrefsKeys.RegisterKey("PlayFabID");
|
|
|
|
|
//PlayerPrefs.Save();
|
|
|
|
|
|
|
|
|
|
LoadPlayerPrefsFromPlayFab(() =>
|
|
|
|
|
{
|
|
|
|
@ -133,8 +145,34 @@ public class GoogleSignInManager : MonoBehaviour
|
|
|
|
|
{
|
|
|
|
|
foreach (var entry in result.Data)
|
|
|
|
|
{
|
|
|
|
|
PlayerPrefs.SetString(entry.Key, entry.Value.Value);
|
|
|
|
|
PlayerPrefsKeys.RegisterKey(entry.Key);
|
|
|
|
|
string key = entry.Key;
|
|
|
|
|
string rawValue = entry.Value.Value;
|
|
|
|
|
|
|
|
|
|
if (rawValue.StartsWith("int:"))
|
|
|
|
|
{
|
|
|
|
|
if (int.TryParse(rawValue.Substring(4), out int intVal))
|
|
|
|
|
{
|
|
|
|
|
SafePlayerPrefs.SetInt(key, intVal);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (rawValue.StartsWith("float:"))
|
|
|
|
|
{
|
|
|
|
|
if (float.TryParse(rawValue.Substring(6), out float floatVal))
|
|
|
|
|
{
|
|
|
|
|
SafePlayerPrefs.SetFloat(key, floatVal);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (rawValue.StartsWith("string:"))
|
|
|
|
|
{
|
|
|
|
|
SafePlayerPrefs.SetString(key, rawValue.Substring(7));
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
// Backward compatibility: if value has no type prefix, store as string
|
|
|
|
|
SafePlayerPrefs.SetString(key, rawValue);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
PlayerPrefsKeys.RegisterKey(key);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
PlayerPrefs.Save();
|
|
|
|
|