chip-gameV3/Assets/Scripts/Common/CoinCounter.cs

43 lines
1.1 KiB
C#

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