You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
45 lines
1.1 KiB
C#
45 lines
1.1 KiB
C#
using System;
|
|
using UnityEngine;
|
|
|
|
public static class GameConstants
|
|
{
|
|
private const string CashKey = "Cash";
|
|
private const string CarSelectedKey = "CarSelected";
|
|
private const string CarUnlockedPrefix = "CarUnlocked_";
|
|
private const string CarColorIndexKey = "CarColorIndex";
|
|
|
|
public static event Action<int> OnCashChanged;
|
|
|
|
public static int CarColorIndex
|
|
{
|
|
get => PlayerPrefs.GetInt(CarColorIndexKey, 0);
|
|
set => PlayerPrefs.SetInt(CarColorIndexKey, value);
|
|
}
|
|
|
|
public static int Cash
|
|
{
|
|
get => PlayerPrefs.GetInt(CashKey, 0);
|
|
set
|
|
{
|
|
PlayerPrefs.SetInt(CashKey, value);
|
|
OnCashChanged?.Invoke(value); // 🔔 Notify all listeners
|
|
}
|
|
}
|
|
|
|
public static int CarSelected
|
|
{
|
|
get => PlayerPrefs.GetInt(CarSelectedKey, 0);
|
|
set => PlayerPrefs.SetInt(CarSelectedKey, value);
|
|
}
|
|
|
|
public static bool IsCarUnlocked(int index)
|
|
{
|
|
return PlayerPrefs.GetInt(CarUnlockedPrefix + index, index == 0 ? 1 : 0) == 1;
|
|
}
|
|
|
|
public static void UnlockCar(int index)
|
|
{
|
|
PlayerPrefs.SetInt(CarUnlockedPrefix + index, 1);
|
|
}
|
|
}
|