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.
Driftology/Assets/Scripts/GameConstants.cs

51 lines
1.4 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;
private const string PlayerNameKey = "PlayerName";
public static string PlayerName
{
get => PlayerPrefs.GetString(PlayerNameKey, "You");
set => PlayerPrefs.SetString(PlayerNameKey, value);
}
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);
}
}