71 lines
2.2 KiB
C#
71 lines
2.2 KiB
C#
using TMPro;
|
|
using UnityEngine;
|
|
|
|
public class CoinCounter : MonoBehaviour
|
|
{
|
|
public TextMeshProUGUI balanceLabel;
|
|
public TextMeshProUGUI revengeLabel;
|
|
|
|
[SerializeField] private Color revengePriceColor = new Color(1f, 0.16f, 0f);
|
|
|
|
[Header("VFX")]
|
|
[SerializeField] private ParticleSystem AddCoinsPS;
|
|
[SerializeField] private ParticleSystem RemoveCoinsPS;
|
|
|
|
[Header("No coins animation")]
|
|
[SerializeField] private float amplitude;
|
|
[SerializeField] private float animationSpeed;
|
|
|
|
private bool initialized = false;
|
|
|
|
private void EmitAdd(int delta) => AddCoinsPS.Play();
|
|
private void EmitRemove(int delta) => RemoveCoinsPS.Play();
|
|
|
|
|
|
|
|
void OnEnable() => Init();
|
|
|
|
private void Init()
|
|
{
|
|
SetRevengePriceVisibility(false);
|
|
|
|
UpdateBalanceLabel();
|
|
PaymentSystem.OnBalanceChanged += UpdateBalanceLabel;
|
|
PaymentSystem.onCoinAdded += EmitAdd;
|
|
PaymentSystem.onCoinRemoved += EmitRemove;
|
|
SettingsManager.OnSettingsChanged.AddListener(UpdateBalanceLabel);
|
|
|
|
initialized = true;
|
|
}
|
|
|
|
private void OnDisable()
|
|
{
|
|
if (!initialized) return;
|
|
|
|
PaymentSystem.OnBalanceChanged -= UpdateBalanceLabel;
|
|
PaymentSystem.onCoinAdded -= EmitAdd;
|
|
PaymentSystem.onCoinRemoved -= EmitRemove;
|
|
SettingsManager.OnSettingsChanged.RemoveListener(UpdateBalanceLabel);
|
|
}
|
|
|
|
private void UpdateBalanceLabel() => UpdateBalanceLabel(PaymentSystem.Balance);
|
|
|
|
public void UpdateBalanceLabel(int newCount)
|
|
{
|
|
balanceLabel.text = $"Баланс:<br>{newCount} {PaymentSystem.ValutaName}";
|
|
}
|
|
|
|
public void SetRevengePriceVisibility(bool visibility)
|
|
{
|
|
if (PaymentSystem.PriceRevenge < PaymentSystem.PricePve)
|
|
{
|
|
revengeLabel.text = $"Цена игры: <br><s>{PaymentSystem.PricePve} {PaymentSystem.ValutaName}</s><br>" +
|
|
$"Повторная игра:<br> {PaymentSystem.PriceRevenge} {PaymentSystem.ValutaName}".UnderlineWrap().ColorWrap(revengePriceColor);
|
|
}
|
|
else
|
|
{
|
|
revengeLabel.text = $"Повторная игра:<br><u>{PaymentSystem.PriceRevenge} {PaymentSystem.ValutaName}</u>";
|
|
}
|
|
revengeLabel.alpha = visibility ? 1 : 0;
|
|
}
|
|
} |