Добавить таймеры и шкалы прогресса, расширить призовую систему и контроль остатков, восстановить настройки и обновить таблицу призов главного меню.
57 lines
1.6 KiB
C#
57 lines
1.6 KiB
C#
using System;
|
|
using UnityEngine;
|
|
|
|
namespace PrizeSystem
|
|
{
|
|
public static class PrizeStockService
|
|
{
|
|
public static event Action StateChanged;
|
|
|
|
public static int Count => Mathf.Max(PlayerPrefs.GetInt(PrefsKeyVault.PRIZES_AVAILABLE, 0), 0);
|
|
public static bool Enabled => SettingsManager.Initialized
|
|
&& SettingsManager.GetBool(SettingKey.PRIZE_STOCK_CONTROL);
|
|
|
|
public static void Initialize()
|
|
{
|
|
PlayerPrefs.SetInt(PrefsKeyVault.PRIZES_AVAILABLE, Count);
|
|
SettingsManager.OnSettingsChanged -= NotifyStateChanged;
|
|
SettingsManager.OnSettingsChanged += NotifyStateChanged;
|
|
StateChanged?.Invoke();
|
|
}
|
|
|
|
public static void Add(int amount)
|
|
{
|
|
if (amount <= 0)
|
|
return;
|
|
|
|
SetCount(Count + amount);
|
|
}
|
|
|
|
public static void SetCount(int count)
|
|
{
|
|
int normalizedCount = Mathf.Clamp(count, 0, 999999);
|
|
|
|
if (normalizedCount == Count)
|
|
return;
|
|
|
|
PlayerPrefs.SetInt(PrefsKeyVault.PRIZES_AVAILABLE, normalizedCount);
|
|
PlayerPrefs.Save();
|
|
StateChanged?.Invoke();
|
|
}
|
|
|
|
public static void SetEnabled(bool enabled)
|
|
=> SettingsManager.SetBool(SettingKey.PRIZE_STOCK_CONTROL, enabled);
|
|
|
|
public static void RecordSuccessfulCountableIssue()
|
|
{
|
|
if (Enabled == false)
|
|
return;
|
|
|
|
SetCount(Count - 1);
|
|
}
|
|
|
|
private static void NotifyStateChanged()
|
|
=> StateChanged?.Invoke();
|
|
}
|
|
}
|