using Core.Economy;
|
using KTGMGemClient;
|
using TMPro;
|
using TowerDefense.Level;
|
using UnityEngine;
|
|
namespace TowerDefense.UI.HUD
|
{
|
/// <summary>
|
/// A class for controlling the displaying the currency
|
/// </summary>
|
public class EndlessCurrencyUI : MonoBehaviour
|
{
|
/// <summary>
|
/// TextMeshPro对应的金币数据
|
/// </summary>
|
public TextMeshProUGUI DisplayText;
|
|
protected Currency currency;
|
|
private ParticleSystem goldGetPs;//金币获得动画
|
|
private void Start()
|
{
|
goldGetPs = transform.Find("CurrencyImage/Effect_UI_JinBi_HuoDe/Particle System (6)").GetComponent<ParticleSystem>();
|
|
if (EndlessLevelManager.instanceExists)
|
{
|
currency = EndlessLevelManager.instance.Currency;
|
|
UpdateDisplay();
|
currency.currencyChanged += UpdateDisplay;
|
}
|
else
|
Debug.LogError("[UI] No EndlessLevelManager to get currency from");
|
|
EventCenter.Ins.Add((int)KTGMGemClient.EventType.PlayGetGoldPS, PlayGetGoldPS);
|
}
|
|
/// <summary>
|
/// Unsubscribe from events
|
/// </summary>
|
protected virtual void OnDestroy()
|
{
|
if (currency != null)
|
currency.currencyChanged -= UpdateDisplay;
|
}
|
|
/// <summary>
|
/// A method for updating the display based on the current currency
|
/// </summary>
|
protected void UpdateDisplay()
|
{
|
int current = currency.currentCurrency;
|
//DisplayText.text = AddNumberSemi(current.ToString());
|
DisplayText.text = current.ToString();
|
|
}
|
|
public void PlayGetGoldPS(){
|
goldGetPs.Play();
|
}
|
|
/// <summary>
|
/// 在数字中加入逗号
|
/// </summary>
|
/// <param name="str"></param>
|
protected string AddNumberSemi(string str)
|
{
|
int len = str.Length;
|
for (int ipos = len - 3; ipos > 0; ipos -= 3)
|
{
|
str = str.Insert(ipos, ",");
|
}
|
return str;
|
}
|
}
|
}
|