| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283 |
- 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<int, int, NoOptions> 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();
- }
- }
- }
|