101 lines
3.7 KiB
C#
101 lines
3.7 KiB
C#
using System.Collections.Concurrent;
|
||
using System.Collections.Generic;
|
||
using UnityEngine;
|
||
|
||
public class CountersCollector : MonoBehaviour
|
||
{
|
||
public static ConcurrentDictionary<string, string> Counters = new();
|
||
|
||
void Awake()
|
||
{
|
||
InvokeRepeating("Refresh", 0, 5);
|
||
}
|
||
|
||
private static readonly CounterData[] _counterConfigs =
|
||
{
|
||
// Призовые счетчики глобальные
|
||
new CounterData(PrizeSystem.HopperPrizeCounter, "Хоппер", 0),
|
||
new CounterData(PrizeSystem.TicketPrizeCounter, "Тикетник", 0),
|
||
new CounterData(PrizeSystem.MarblesPrizeCounter, "Марблс", 0),
|
||
new CounterData(PrizeSystem.SpecialPrizeCounter, "Суперприз", 0),
|
||
|
||
// Призовые счетчики обнуляемые
|
||
new CounterData($"{PrizeSystem.HopperPrizeCounter}Nullable", "Хоппер (обнуляемый)", 0),
|
||
new CounterData($"{PrizeSystem.TicketPrizeCounter}Nullable", "Тикетник (обнуляемый)", 0),
|
||
new CounterData($"{PrizeSystem.MarblesPrizeCounter}Nullable", "Марблс (обнуляемый)", 0),
|
||
new CounterData($"{PrizeSystem.SpecialPrizeCounter}Nullable", "Суперприз (обнуляемый)", 0),
|
||
|
||
// Выручка
|
||
new CounterData(PrizeSystem.key_cash, "Выручка", 0),
|
||
new CounterData(PrizeSystem.key_cashNul, "Выручка (обнуляемый)", 0),
|
||
|
||
// Остаток призов
|
||
new CounterData(KeyVault.PRIZES_AVAILABLE, "Остаток призов", 0),
|
||
|
||
// Цены
|
||
new CounterData("PricePVP", "Цена на двоих", 10),
|
||
new CounterData("PricePVE", "Цена против бота", 10),
|
||
new CounterData("PriceRevenge", "Цена реванша", 10),
|
||
|
||
// Расчеты
|
||
new CounterData("ValutaName", "Название валюты", "руб."),
|
||
new CounterData("ValutaPerImpulse", "Валюта за импульс", 10),
|
||
|
||
// Другое
|
||
new CounterData("Number", "Номер телефона", "<не указан>"),
|
||
new CounterData("SpecialPrize", "Суперприз", "<не указан>")
|
||
|
||
};
|
||
|
||
|
||
void Refresh()
|
||
{
|
||
Counters.Clear();
|
||
foreach (var config in _counterConfigs)
|
||
{
|
||
AddCounter(config);
|
||
}
|
||
}
|
||
void AddCounter(CounterData counterData)
|
||
{
|
||
string value = counterData.Type == SettingType.Int
|
||
? PlayerPrefs.GetInt(counterData.PrefsKey, counterData.DefaultIntValue).ToString()
|
||
: PlayerPrefs.GetString(counterData.PrefsKey, counterData.DefaultStringValue);
|
||
|
||
Counters[counterData.Alias] = value;
|
||
}
|
||
struct CounterData
|
||
{
|
||
public string PrefsKey;
|
||
public string Alias;
|
||
|
||
public SettingType Type;
|
||
public string DefaultStringValue;
|
||
public int DefaultIntValue;
|
||
|
||
|
||
|
||
/// <summary> Конструктор для строковых счетчиков </summary>
|
||
public CounterData(string prefsKey, string alias, string defaultValue)
|
||
{
|
||
PrefsKey = prefsKey;
|
||
Alias = alias;
|
||
|
||
Type = SettingType.String;
|
||
DefaultStringValue = defaultValue;
|
||
DefaultIntValue = 0;
|
||
}
|
||
|
||
/// <summary> Конструктор для целочисленных счетчиков </summary>
|
||
public CounterData(string prefsKey, string alias, int defaultValue)
|
||
{
|
||
PrefsKey = prefsKey;
|
||
Alias = alias;
|
||
|
||
Type = SettingType.Int;
|
||
DefaultStringValue = string.Empty;
|
||
DefaultIntValue = defaultValue;
|
||
}
|
||
}
|
||
}
|