68 lines
2.0 KiB
C#
68 lines
2.0 KiB
C#
using System;
|
|
using UnityEngine;
|
|
|
|
namespace BlockSpace.Account
|
|
{
|
|
public static class BlockSpaceAccountPrefs
|
|
{
|
|
public const string LinkedKey = "BlockSpace.Account.Linked";
|
|
|
|
public const string LinkedPlayerIdKey = "BlockSpace.Account.PlayerId";
|
|
|
|
public const string LinkedDiscordIdKey = "BlockSpace.Account.DiscordId";
|
|
|
|
public const string LinkedDiscordDisplayNameKey = "BlockSpace.Account.DiscordDisplayName";
|
|
|
|
public const string LocalUserIdKey = "BlockSpace.LocalUserId";
|
|
|
|
public static bool IsLinked => PlayerPrefs.GetInt("BlockSpace.Account.Linked", 0) == 1;
|
|
|
|
public static string GetLinkedPlayerId()
|
|
{
|
|
return PlayerPrefs.GetString("BlockSpace.Account.PlayerId", string.Empty);
|
|
}
|
|
|
|
public static string GetDiscordId()
|
|
{
|
|
return PlayerPrefs.GetString("BlockSpace.Account.DiscordId", string.Empty);
|
|
}
|
|
|
|
public static string GetDiscordDisplayName()
|
|
{
|
|
return PlayerPrefs.GetString("BlockSpace.Account.DiscordDisplayName", string.Empty);
|
|
}
|
|
|
|
public static void SetLinkedAccount(string playerId, string discordId, string discordDisplayName)
|
|
{
|
|
PlayerPrefs.SetInt("BlockSpace.Account.Linked", 1);
|
|
PlayerPrefs.SetString("BlockSpace.Account.PlayerId", playerId ?? string.Empty);
|
|
PlayerPrefs.SetString("BlockSpace.Account.DiscordId", discordId ?? string.Empty);
|
|
PlayerPrefs.SetString("BlockSpace.Account.DiscordDisplayName", discordDisplayName ?? string.Empty);
|
|
PlayerPrefs.Save();
|
|
}
|
|
|
|
public static string GetOrCreateLocalUserId()
|
|
{
|
|
string text = PlayerPrefs.GetString("BlockSpace.LocalUserId", string.Empty);
|
|
if (!string.IsNullOrEmpty(text))
|
|
{
|
|
return text;
|
|
}
|
|
string text2 = Guid.NewGuid().ToString("N");
|
|
PlayerPrefs.SetString("BlockSpace.LocalUserId", text2);
|
|
PlayerPrefs.Save();
|
|
return text2;
|
|
}
|
|
|
|
public static string GetUserFolderId()
|
|
{
|
|
string linkedPlayerId = GetLinkedPlayerId();
|
|
if (string.IsNullOrEmpty(linkedPlayerId))
|
|
{
|
|
return GetOrCreateLocalUserId();
|
|
}
|
|
return linkedPlayerId;
|
|
}
|
|
}
|
|
}
|