| | |
| | | using Core.Economy; |
| | | using KTGMGemClient; |
| | | using TMPro; |
| | | using TowerDefense.Level; |
| | | using UnityEngine; |
| | | using DG.Tweening; |
| | | using Core.Utilities; |
| | | |
| | | namespace TowerDefense.UI.HUD |
| | | { |
| | |
| | | |
| | | protected Currency currency; |
| | | |
| | | private ParticleSystem goldGetPs;//金币获得动画 |
| | | |
| | | /// <summary> |
| | | /// 每秒增加的金币数量 |
| | | /// </summary> |
| | | private int addCurrencyPerSecond; |
| | | |
| | | private float duration; |
| | | |
| | | /// <summary> |
| | | /// 一秒前金币 |
| | | /// </summary> |
| | | private int lastCurrency; |
| | | |
| | | [SerializeField] |
| | | private GameObject addCurrencyPrefab; |
| | | |
| | | private void Start() |
| | | { |
| | | goldGetPs = transform.Find("CurrencyImage/Effect_UI_JinBi_HuoDe/Particle System (6)").GetComponent<ParticleSystem>(); |
| | | |
| | | if (EndlessLevelManager.instanceExists) |
| | | { |
| | | currency = EndlessLevelManager.instance.Currency; |
| | |
| | | } |
| | | else |
| | | Debug.LogError("[UI] No EndlessLevelManager to get currency from"); |
| | | |
| | | EventCenter.Ins.Add((int)KTGMGemClient.EventType.PlayGetGoldPS, PlayGetGoldPS); |
| | | } |
| | | |
| | | /// <summary> |
| | |
| | | protected void UpdateDisplay() |
| | | { |
| | | int current = currency.currentCurrency; |
| | | //DisplayText.text = AddNumberSemi(current.ToString()); |
| | | int lastCurrency = currency.lastCurrency; |
| | | DisplayText.text = current.ToString(); |
| | | |
| | | if (lastCurrency > 0 && current - lastCurrency > 0) |
| | | ToBig().OnComplete(ToSmall); |
| | | } |
| | | |
| | | private Tweener ToBig() |
| | | { |
| | | return DOTween.To( |
| | | () => DisplayText.transform.localScale, |
| | | (Vector3 v) => DisplayText.transform.localScale = v, |
| | | new Vector3(1.15f, 1.15f, 1.15f), |
| | | 0.15f); |
| | | } |
| | | |
| | | private void ToSmall() |
| | | { |
| | | DOTween.To( |
| | | () => DisplayText.transform.localScale, |
| | | (Vector3 v) => DisplayText.transform.localScale = v, |
| | | new Vector3(1f, 1f, 1f), |
| | | 0.1f); |
| | | } |
| | | |
| | | public void PlayGetGoldPS() |
| | | { |
| | | goldGetPs.Play(); |
| | | } |
| | | |
| | | /// <summary> |
| | |
| | | } |
| | | return str; |
| | | } |
| | | |
| | | private void Update() |
| | | { |
| | | FloatAddCurrency(); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 飘1s内增加的金币 |
| | | /// </summary> |
| | | private void FloatAddCurrency() |
| | | { |
| | | if (duration <= 0.0001f) |
| | | { |
| | | lastCurrency = currency.currentCurrency; |
| | | } |
| | | |
| | | duration += Time.deltaTime; |
| | | |
| | | if (duration >= 1f) |
| | | { |
| | | int add = currency.currentCurrency - lastCurrency; |
| | | |
| | | if (add > 0) |
| | | { |
| | | GameObject obj = Instantiate(addCurrencyPrefab); |
| | | obj.transform.SetParent(GameObject.Find("UICamera/BottomCanvas/Panel/Bottom/CurrencyContainer").transform, false); |
| | | obj.transform.localPosition = new Vector3(148f, -30f, 0f); |
| | | obj.transform.localScale = new Vector3(0.66f, 0.66f, 0.66f); |
| | | TextMeshProUGUI textMeshProUGUI = obj.GetComponent<TextMeshProUGUI>(); |
| | | textMeshProUGUI.text = $"+{add}"; |
| | | |
| | | DOTween.To( |
| | | () => obj.transform.localPosition.y, |
| | | (float v) => |
| | | { |
| | | Vector3 pos = obj.transform.localPosition; |
| | | pos.y = v; |
| | | obj.transform.localPosition = pos; |
| | | }, |
| | | -20f, 0.2f); |
| | | Destroy(obj, 0.5f); |
| | | } |
| | | |
| | | duration = 0f; |
| | | } |
| | | } |
| | | } |
| | | } |