45 lines
1.2 KiB
C#
45 lines
1.2 KiB
C#
using TMPro;
|
|
using UnityEngine;
|
|
|
|
public class CoinCounter : MonoBehaviour
|
|
{
|
|
public TextMeshProUGUI balanceLabel;
|
|
public CanvasGroup balanceSignGroup;
|
|
private bool initialized = false;
|
|
|
|
void OnEnable() => Init();
|
|
|
|
private void Init()
|
|
{
|
|
UpdateBalanceLabelBySettings();
|
|
PaymentSystem.OnBalanceChanged += UpdateBalanceLabel;
|
|
SettingsManager.OnSettingsChanged.AddListener(UpdateBalanceLabelBySettings);
|
|
|
|
initialized = true;
|
|
}
|
|
|
|
private void OnDisable()
|
|
{
|
|
if (!initialized) return;
|
|
|
|
PaymentSystem.OnBalanceChanged -= UpdateBalanceLabel;
|
|
SettingsManager.OnSettingsChanged.RemoveListener(UpdateBalanceLabelBySettings);
|
|
}
|
|
|
|
private void UpdateBalanceLabelBySettings()
|
|
{
|
|
bool freeplay = SettingsManager.GetBool(SettingKeys.FREEPLAY, false);
|
|
if(freeplay)
|
|
{
|
|
balanceLabel.text = "бесплатно";
|
|
balanceSignGroup.alpha = 0;
|
|
}
|
|
else
|
|
{
|
|
UpdateBalanceLabel(PaymentSystem.Balance);
|
|
balanceSignGroup.alpha = 1;
|
|
}
|
|
}
|
|
|
|
public void UpdateBalanceLabel(int newCount) => balanceLabel.text = $"{newCount} {PaymentSystem.ValutaName}";
|
|
} |