Fixed Sign In with data fetching

hazim-dev
Ali Sharoz 2 weeks ago
parent 5b756716ea
commit 539aef3d33

@ -109,7 +109,7 @@ namespace D2D.Databases
private void SaveMoney(float val)
{
PlayerPrefs.SetInt("Money", Money.Value.Round());
SafePlayerPrefs.SetInt("Money", Money.Value.Round());
}
private void OnApplicationQuit()
@ -151,7 +151,7 @@ namespace D2D.Databases
ES3.Save("LastUnlockedMember", "");
ES3.Save(UnlockedMembersKey, new List<string>());
PlayerPrefs.SetInt("Money", 0);
SafePlayerPrefs.SetInt("Money", 0);
}
}
}

@ -855,7 +855,7 @@ public static class ES3
}
else if (oldSettings.location == Location.PlayerPrefs)
{
PlayerPrefs.SetString(newSettings.FullPath, PlayerPrefs.GetString(oldSettings.FullPath));
SafePlayerPrefs.SetString(newSettings.FullPath, PlayerPrefs.GetString(oldSettings.FullPath));
}
else if (oldSettings.location == Location.Cache)
{
@ -901,7 +901,7 @@ public static class ES3
}
else if (oldSettings.location == Location.PlayerPrefs)
{
PlayerPrefs.SetString(newSettings.FullPath, PlayerPrefs.GetString(oldSettings.FullPath));
SafePlayerPrefs.SetString(newSettings.FullPath, PlayerPrefs.GetString(oldSettings.FullPath));
PlayerPrefs.DeleteKey(oldSettings.FullPath);
}
else if (oldSettings.location == Location.Cache)

@ -128,7 +128,7 @@ namespace ES3Internal
}
else if(settings.location == ES3.Location.PlayerPrefs)
{
PlayerPrefs.SetString(settings.FullPath, PlayerPrefs.GetString(settings.FullPath + temporaryFileSuffix));
SafePlayerPrefs.SetString(settings.FullPath, PlayerPrefs.GetString(settings.FullPath + temporaryFileSuffix));
PlayerPrefs.DeleteKey(settings.FullPath + temporaryFileSuffix);
PlayerPrefs.Save();
}

@ -48,14 +48,14 @@ namespace ES3Internal
System.Buffer.BlockCopy(sourceBytes, 0, finalBytes, 0, sourceBytes.Length);
System.Buffer.BlockCopy(appendBytes, 0, finalBytes, sourceBytes.Length, appendBytes.Length);
PlayerPrefs.SetString(path, System.Convert.ToBase64String(finalBytes));
SafePlayerPrefs.SetString(path, System.Convert.ToBase64String(finalBytes));
PlayerPrefs.Save();
}
else
PlayerPrefs.SetString(path + ES3IO.temporaryFileSuffix, System.Convert.ToBase64String(this.ToArray()));
// Save the timestamp to a separate key.
PlayerPrefs.SetString("timestamp_" + path, System.DateTime.UtcNow.Ticks.ToString());
SafePlayerPrefs.SetString(path + ES3IO.temporaryFileSuffix, System.Convert.ToBase64String(this.ToArray()));
// Save the timestamp to a separate key.
SafePlayerPrefs.SetString("timestamp_" + path, System.DateTime.UtcNow.Ticks.ToString());
}
base.Dispose(disposing);
}

@ -128,7 +128,7 @@ public class AchievementManager : MonoBehaviour
int coins = PlayerPrefs.GetInt("Coin");
Debug.Log(toAdd + " Coins Rewarded");
coins += toAdd;
PlayerPrefs.SetInt("Coin", coins);
SafePlayerPrefs.SetInt("Coin", coins);
StartCoroutine(startCoinShakeEffect(coins - toAdd, coins, .5f));
}
@ -169,12 +169,12 @@ public class AchievementManager : MonoBehaviour
#region Ali's Code for Reward
PlayerPrefs.SetInt("UIAchievement" + Index + "Claimable", 1);
SafePlayerPrefs.SetInt("UIAchievement" + Index + "Claimable", 1);
int numOfPrevCoins = PlayerPrefs.GetInt("TotalCoinsForReward" + Index, 0);
int subAchievementIndex = PlayerPrefs.GetInt("subAchievementIndex" + Index, 0);
PlayerPrefs.SetInt("TotalCoinsForReward" + Index, numOfPrevCoins + achievementInfromation.CoinRewards[Mathf.Clamp(subAchievementIndex,0, achievementInfromation.CoinRewards.Count-1)]);
SafePlayerPrefs.SetInt("TotalCoinsForReward" + Index, numOfPrevCoins + achievementInfromation.CoinRewards[Mathf.Clamp(subAchievementIndex,0, achievementInfromation.CoinRewards.Count-1)]);
subAchievementIndex++;
PlayerPrefs.SetInt("subAchievementIndex" + Index, subAchievementIndex);
SafePlayerPrefs.SetInt("subAchievementIndex" + Index, subAchievementIndex);
#endregion
@ -273,7 +273,7 @@ public class AchievementManager : MonoBehaviour
{
for (int i = 0; i < States.Count; i++)
{
PlayerPrefs.SetString("AchievementState_" + i, JsonUtility.ToJson(States[i]));
SafePlayerPrefs.SetString("AchievementState_" + i, JsonUtility.ToJson(States[i]));
}
PlayerPrefs.Save();
}

@ -102,7 +102,7 @@ public class AchievenmentListIngame : MonoBehaviour
{
if (PlayerPrefs.GetInt("UIAchievement" + i + "Claimable") == 1)
{
PlayerPrefs.SetInt("UIAchievement" + i + "Claimable", 0);
SafePlayerPrefs.SetInt("UIAchievement" + i + "Claimable", 0);
Stack[i].Tick.SetActive(true);
Stack[i].ClaimButton.gameObject.SetActive(true);
@ -112,7 +112,7 @@ public class AchievenmentListIngame : MonoBehaviour
Stack[i].ClaimButton.onClick.AddListener(() =>
{
AchievementManager.instance.AddCoins(numofCoinsToAdd);
PlayerPrefs.SetInt("TotalCoinsForReward" + i, 0);
SafePlayerPrefs.SetInt("TotalCoinsForReward" + i, 0);
});
}
}

@ -35,7 +35,7 @@ public class UIAchievement : MonoBehaviour
int RewardtoAdd = Information.CoinRewards[subAchievementIndex];
int TotalReward = RewardtoAdd + CurrentTotalReward;
Information.TotalCoinReward = TotalReward;
PlayerPrefs.SetInt("TotalRewards"+index, TotalReward);
SafePlayerPrefs.SetInt("TotalRewards"+index, TotalReward);
}
/// <summary>

@ -19,7 +19,7 @@ public class AudioSourceController : MonoBehaviour
// Ensure default music is ON if running for the first time
if (!PlayerPrefs.HasKey("MusicBool"))
{
PlayerPrefs.SetInt("MusicBool", 1); // Default to ON
SafePlayerPrefs.SetInt("MusicBool", 1); // Default to ON
PlayerPrefs.Save();
}
@ -42,10 +42,10 @@ public class AudioSourceController : MonoBehaviour
{
if (VolScroll != null)
{
PlayerPrefs.SetFloat("Volume", VolScroll.value);
SafePlayerPrefs.SetFloat("Volume", VolScroll.value);
}
PlayerPrefs.SetInt("MusicBool", OffButton.activeSelf ? 1 : 0);
SafePlayerPrefs.SetInt("MusicBool", OffButton.activeSelf ? 1 : 0);
PlayerPrefs.Save(); // Ensure immediate save
// Update last saved state

@ -1,7 +1,8 @@
{
"name": "MoreMountains.Tools.Editor",
"references": [
"GUID:4a1cb1490dc4df8409b2580d6b44e75e"
"GUID:4a1cb1490dc4df8409b2580d6b44e75e",
"Assembly-CSharp"
],
"includePlatforms": [
"Editor"
@ -13,4 +14,4 @@
"autoReferenced": true,
"defineConstraints": [],
"versionDefines": []
}
}

@ -104,11 +104,11 @@ public class Advertisements : MonoBehaviour
{
if (accept == true)
{
PlayerPrefs.SetInt(userConsent, (int)UserConsent.Accept);
SafePlayerPrefs.SetInt(userConsent, (int)UserConsent.Accept);
}
else
{
PlayerPrefs.SetInt(userConsent, (int)UserConsent.Deny);
SafePlayerPrefs.SetInt(userConsent, (int)UserConsent.Deny);
}
if (initialized == true)
{
@ -125,11 +125,11 @@ public class Advertisements : MonoBehaviour
{
if (accept == true)
{
PlayerPrefs.SetInt(ccpaConsent, (int)UserConsent.Accept);
SafePlayerPrefs.SetInt(ccpaConsent, (int)UserConsent.Accept);
}
else
{
PlayerPrefs.SetInt(ccpaConsent, (int)UserConsent.Deny);
SafePlayerPrefs.SetInt(ccpaConsent, (int)UserConsent.Deny);
}
if (initialized == true)
{
@ -196,13 +196,13 @@ public class Advertisements : MonoBehaviour
{
if (remove == true)
{
PlayerPrefs.SetInt(removeAds, 1);
SafePlayerPrefs.SetInt(removeAds, 1);
//if banner is active and user bought remove ads the banner will automatically hide
HideBanner();
}
else
{
PlayerPrefs.SetInt(removeAds, 0);
SafePlayerPrefs.SetInt(removeAds, 0);
}
}

@ -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();

@ -1,6 +1,6 @@
{
"name": "Unity.PlayerPrefsEditor.Samples.SampleScene",
"references": [],
"references": ["Assembly-CSharp"],
"optionalUnityReferences": [],
"includePlatforms": [],
"excludePlatforms": [],

@ -2,23 +2,29 @@
using PlayFab;
using PlayFab.ClientModels;
using System.Collections.Generic;
using Google.Impl;
public class PlayerPrefsSyncManager : MonoBehaviour
{
private static PlayerPrefsSyncManager instance;
private void OnApplicationQuit()
{
SyncPlayerPrefsToPlayFabOnQuit();
}
private void OnApplicationPause()
{
SyncPlayerPrefsToPlayFabOnQuit();
}
private void OnApplicationFocus(bool focus)
{
if (!focus)
SyncPlayerPrefsToPlayFabOnQuit();
}
void Awake()
{
// Make this object persistent across scenes
if (instance == null)
{
instance = this;
@ -31,7 +37,9 @@ public class PlayerPrefsSyncManager : MonoBehaviour
}
}
private void SyncPlayerPrefsToPlayFabOnQuit()
private const int MaxKeysPerRequest = 10;
public void SyncPlayerPrefsToPlayFabOnQuit()
{
var keys = PlayerPrefsKeys.GetAllKeys();
if (keys.Count == 0)
@ -44,17 +52,78 @@ public class PlayerPrefsSyncManager : MonoBehaviour
foreach (var key in keys)
{
string value = PlayerPrefs.GetString(key);
allPrefs[key] = value;
string strVal = PlayerPrefs.GetString(key, "__MISSING__");
if (strVal != "__MISSING__")
{
allPrefs[key] = "string:" + strVal;
continue;
}
int intVal = PlayerPrefs.GetInt(key, int.MinValue + 1);
if (intVal != int.MinValue + 1)
{
allPrefs[key] = "int:" + intVal;
continue;
}
float floatVal = PlayerPrefs.GetFloat(key, float.MinValue + 1);
if (floatVal != float.MinValue + 1)
{
allPrefs[key] = "float:" + floatVal.ToString("R");
}
}
foreach (var pair in allPrefs)
{
Debug.Log($"[Sync] {pair.Key} = {pair.Value}");
}
// Split into batches of 10
var batches = new List<Dictionary<string, string>>();
var currentBatch = new Dictionary<string, string>();
foreach (var pair in allPrefs)
{
currentBatch[pair.Key] = pair.Value;
if (currentBatch.Count == MaxKeysPerRequest)
{
batches.Add(currentBatch);
currentBatch = new Dictionary<string, string>();
}
}
if (currentBatch.Count > 0)
{
batches.Add(currentBatch);
}
UploadPlayerPrefsBatches(batches, 0);
}
private void UploadPlayerPrefsBatches(List<Dictionary<string, string>> batches, int index)
{
if (index >= batches.Count)
{
Debug.Log("✅ All PlayerPrefs batches synced to PlayFab.");
return;
}
var request = new UpdateUserDataRequest
{
Data = allPrefs
Data = batches[index],
Permission = UserDataPermission.Public
};
PlayFabClientAPI.UpdateUserData(request,
result => Debug.Log("✅ Synced PlayerPrefs to PlayFab on quit."),
error => Debug.LogError("❌ Failed to sync PlayerPrefs on quit: " + error.GenerateErrorReport()));
result =>
{
Debug.Log($"✅ Synced batch {index + 1}/{batches.Count}");
UploadPlayerPrefsBatches(batches, index + 1);
},
error =>
{
Debug.LogError($"❌ Failed to sync batch {index + 1}/{batches.Count}: {error.GenerateErrorReport()}");
});
}
}

@ -71,8 +71,8 @@ public class Profile : MonoBehaviour
public void OnDisplayNameEntered()
{
PlayFabManager.Instance.playFabLeaderboards.SetDisplayName(nameInputField.text);
PlayerPrefs.SetInt(GameConstants.NameEnteredCheckKey, 1);
PlayerPrefs.SetString(GameConstants.DisplayNameKey, nameInputField.text);
SafePlayerPrefs.SetInt(GameConstants.NameEnteredCheckKey, 1);
SafePlayerPrefs.SetString(GameConstants.DisplayNameKey, nameInputField.text);
HeaderProfileName.text = nameInputField.text;
EnterNamePanel.Close();
@ -82,8 +82,8 @@ public class Profile : MonoBehaviour
{
//PlayFabManager.Instance.playFabLeaderboards.SetDisplayName(nameInputField.text);
EnteredNameButton.interactable = true;
PlayerPrefs.SetInt(GameConstants.AvatarSelectedCheckKey, 1);
PlayerPrefs.SetInt(GameConstants.AvatarSelectedIndex, AvatarID);
SafePlayerPrefs.SetInt(GameConstants.AvatarSelectedCheckKey, 1);
SafePlayerPrefs.SetInt(GameConstants.AvatarSelectedIndex, AvatarID);
AvatarSelectedSprite = AvatarSprites[AvatarID];
HeaderProfileImg.sprite = AvatarSelectedSprite;
SetAvatarID(AvatarID);

@ -15,7 +15,7 @@ public class DataManager
set
{
val = value;
PlayerPrefs.SetInt(_pref_VAL, val);
SafePlayerPrefs.SetInt(_pref_VAL, val);
}
}
int currentlevelindex = 0;
@ -26,7 +26,7 @@ public class DataManager
set
{
currentlevelindex = value;
PlayerPrefs.SetInt(_pref_CURRENTLEVELINDEX, currentlevelindex);
SafePlayerPrefs.SetInt(_pref_CURRENTLEVELINDEX, currentlevelindex);
}
}
int maxlevelindex = 0;
@ -37,7 +37,7 @@ public class DataManager
set
{
maxlevelindex = value;
PlayerPrefs.SetInt(_pref_MAXLEVELINDEX, maxlevelindex);
SafePlayerPrefs.SetInt(_pref_MAXLEVELINDEX, maxlevelindex);
}
}

@ -51,7 +51,7 @@ public class CharacterSelectionUI : MonoBehaviour
// Saves the currently selected character index to PlayerPrefs
void SaveSelection()
{
PlayerPrefs.SetInt(Constants.PlayerSelectionKey, currentIndex);
SafePlayerPrefs.SetInt(Constants.PlayerSelectionKey, currentIndex);
PlayerPrefs.Save();
Debug.Log("Character " + currentIndex + " selected and saved.");
// GameProgressionDatabase.ResetLevelsPerSession();

@ -9,7 +9,7 @@ public class EventManager : MonoBehaviour
[ContextMenu("CoinIncreaserCaller")]
public void CoinIncreaserCaller()
{
PlayerPrefs.SetInt("Money", PlayerPrefs.GetInt("Money") + 10);
SafePlayerPrefs.SetInt("Money", PlayerPrefs.GetInt("Money") + 10);
CoinIncreaser();
}
}

@ -104,7 +104,7 @@ public class ShopManager : MonoBehaviour, IDetailedStoreListener
if (IsProductPurchased(pItem[i].Id))
{
//PlayerPrefs.SetInt("PipeButtonIsEquipped" + 0, 1);
PlayerPrefs.SetInt("PipeButtonIsPurchased" + i, 1);
SafePlayerPrefs.SetInt("PipeButtonIsPurchased" + i, 1);
Debug.Log("Pipe " + i + " is purchased already!");
// Product is purchased, grant access to features
}
@ -392,7 +392,7 @@ public class ShopManager : MonoBehaviour, IDetailedStoreListener
int coins = PlayerPrefs.GetInt("Money");
Debug.Log(toAdd + " Coins purchased");
coins += toAdd;
PlayerPrefs.SetInt("Coin", coins);
SafePlayerPrefs.SetInt("Coin", coins);
StartCoroutine(startCoinShakeEffect(coins - toAdd, coins, .5f));
}
//public void EquipUnEquipPipe(int buttonIndex)

@ -28,7 +28,7 @@ public class SoundSwitcher : MonoBehaviour
{
float value = PlayerPrefs.GetFloat(MasterVolume, 0);
PlayerPrefs.SetFloat(MasterVolume, value == 0 ? Mute : 0);
SafePlayerPrefs.SetFloat(MasterVolume, value == 0 ? Mute : 0);
audioMixer.SetFloat(MasterVolume, PlayerPrefs.GetFloat(MasterVolume, 0));

@ -30,7 +30,7 @@ public class VibrationSwitcher : MonoBehaviour
{
float value = PlayerPrefs.GetFloat(Vibration, 0);
PlayerPrefs.SetFloat(Vibration, value == 0 ? 1 : 0);
SafePlayerPrefs.SetFloat(Vibration, value == 0 ? 1 : 0);
bool isActive = PlayerPrefs.GetFloat(Vibration, 0) == 1;
// MMVibrationManager.SetHapticsActive(isActive);

Loading…
Cancel
Save