2025-10-18 03:26:16 +05:00

39 lines
1.1 KiB
C#

using System.Collections.Generic;
using UnityEngine;
public static class ShopUnlocks
{
static string Key(string shop) => $"ShopUnlocks_{shop}";
public static bool IsUnlocked(string id, string shop)
{
if (string.IsNullOrEmpty(id)) return false;
var data = PlayerPrefs.GetString(Key(shop), "");
if (string.IsNullOrEmpty(data)) return false;
var parts = data.Split(',');
for (int i = 0; i < parts.Length; i++) if (parts[i] == id) return true;
return false;
}
public static void Unlock(string id, string shop)
{
if (string.IsNullOrEmpty(id)) return;
var list = new List<string>();
var data = PlayerPrefs.GetString(Key(shop), "");
if (!string.IsNullOrEmpty(data)) list.AddRange(data.Split(','));
if (!list.Contains(id)) list.Add(id);
PlayerPrefs.SetString(Key(shop), string.Join(",", list));
PlayerPrefs.Save();
}
public static void EnsureUnlocked(string id, string shop)
{
if (!IsUnlocked(id, shop)) Unlock(id, shop);
}
public static void Reset(string shop)
{
PlayerPrefs.DeleteKey(Key(shop));
}
}