using UnityEngine; // 所有 PlayerPrefs 的鍵集中在這裡(沿用舊版的鍵名,更新後登入狀態與設定不會消失) public static class Prefs { public const string Uid = "UID"; public const string Token = "Token"; public const string LegacyPassword = "Password"; // 舊版存的密碼,登入成功後刪除 public const string Name = "Name"; public const string Email = "Email"; public const string AccountType = "Type"; public const string CreateTime = "CreateTime"; public const string EmailVerified = "EmailVerified"; public const string Song = "NowPlayingSong"; public const string Level = "NowPlayingLevel"; public const string AudioOffsetMs = "AudioOffsetMs"; public const string VideoBackground = "VideoBackground"; public const string StorageAsked = "StorageAsked"; public static int UserId => PlayerPrefs.GetInt(Uid, 0); public static bool LoggedIn => UserId != 0 && (PlayerPrefs.HasKey(Token) || PlayerPrefs.HasKey(LegacyPassword)); // UID 顯示格式:帳號類型字元 + x + 8 位十六進位 public static string UidText() { int uid = UserId; string type = PlayerPrefs.GetString(AccountType, ""); if (uid == 0 || type == "") return "0x00000000"; char c = type switch { "R" => '0', "A" => 'a', "B" => 'b', "D" => 'f', _ => '?' }; return $"{c}x{uid:X8}"; } public static void SetBool(string key, bool value) => PlayerPrefs.SetInt(key, value ? 1 : 0); public static bool GetBool(string key, bool fallback) => PlayerPrefs.GetInt(key, fallback ? 1 : 0) == 1; }