using System.Collections; using System.Collections.Generic; using UnityEngine; namespace ShotSimulator.UI { using System; using System.Collections; using System.Collections.Generic; using System.Linq; using DG.Tweening; using DG.Tweening.Core; using DG.Tweening.Plugins.Options; using UnityEngine; using UnityEngine.UI; public class JumpingNumberTextComponent : MonoBehaviour { private TweenerCore m_Tweener; private int currentValue; private int endValue; public Text viewText; public Text incNumText; public void Init() { if (m_Tweener != null) { m_Tweener.Kill(); } viewText.text = "0"; incNumText.gameObject.SetActive(false); currentValue = 0; endValue = 0; } public void SetNum(int end) { //incNumText.gameObject.SetActive(true); int incNum = end - endValue; endValue = end; string incNumString = string.Empty; if (incNum > 0) { incNumString = "+"; incNumText.color = Color.red; } else if (incNum < 0) { incNumText.color = Color.green; } else { incNumText.gameObject.SetActive(false); } incNumText.text = incNumString + incNum; if (m_Tweener != null) { m_Tweener.Kill(); } m_Tweener = DOTween.To(GetCurrentValue, SetCurrentValue, end, 2); m_Tweener.onComplete = () => { incNumText.gameObject.SetActive(false); }; } private int GetCurrentValue() { return currentValue; } private void SetCurrentValue(int value) { currentValue = value; viewText.text = currentValue.ToString(); } } }