summaryrefslogtreecommitdiff
path: root/Client/Assets/Scripts/XMainClient/XNumberTween.cs
blob: 2deae725a1836c29655eadb4d2ba0667f04834bf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
using System;
using UILib;
using UnityEngine;
using XMainClient.UI;
using XUtliPoolLib;

namespace XMainClient
{
	public class XNumberTween : MonoBehaviour
	{
		public float tweenDuaration
		{
			get
			{
				return this.m_tweenDuaration;
			}
			set
			{
				this.m_tweenDuaration = value;
				this.userTweenDuaration = value;
			}
		}

		public IXUILabel Label
		{
			get
			{
				return this.m_uiLabel;
			}
		}

		public IXUITweenTool IconTween
		{
			get
			{
				return this.m_uiIconTween;
			}
		}

		private IXUILabel m_uiLabel;

		private IXUITweenTool m_uiIconTween;

		private ulong m_currentNumber = 0UL;

		private ulong m_targetNumber = 0UL;

		private long m_deltaNumber = 0L;

		private string m_tweenPostfix;

		private float m_tweenLeftTime = 0.5f;

		private float m_tweenDuaration = 0.5f;

		public float userTweenDuaration = 0.5f;

		public static XNumberTween Create(Transform t)
		{
			XNumberTween xnumberTween = t.gameObject.GetComponent<XNumberTween>();
			bool flag = xnumberTween == null;
			if (flag)
			{
				xnumberTween = t.gameObject.AddComponent<XNumberTween>();
			}
			Transform transform = t.Find("value");
			bool flag2 = transform != null;
			if (flag2)
			{
				xnumberTween.m_uiLabel = (transform.GetComponent("XUILabel") as IXUILabel);
			}
			transform = t.Find("icon");
			bool flag3 = transform != null;
			if (flag3)
			{
				xnumberTween.m_uiIconTween = (t.Find("icon").GetComponent("XUIPlayTween") as IXUITweenTool);
			}
			return xnumberTween;
		}

		public static XNumberTween Create(IXUILabel label)
		{
			XNumberTween xnumberTween = label.gameObject.AddComponent<XNumberTween>();
			xnumberTween.m_uiLabel = label;
			return xnumberTween;
		}

		public void SetNumberWithTween(ulong target, string postfix = "", bool instant = false, bool dynamicAdjustDuaration = true)
		{
			bool flag = target == this.m_currentNumber || instant;
			if (flag)
			{
				this.m_uiLabel.SetText(XSingleton<UiUtility>.singleton.NumberFormat(target) + postfix);
				this.m_targetNumber = target;
				this.m_currentNumber = target;
			}
			else
			{
				this.m_tweenDuaration = this.userTweenDuaration;
				this.m_targetNumber = target;
				this.m_deltaNumber = (long)(this.m_targetNumber - this.m_currentNumber);
				this.m_tweenPostfix = postfix;
				if (dynamicAdjustDuaration)
				{
					long num = Math.Abs(this.m_deltaNumber);
					bool flag2 = num < 20L;
					if (flag2)
					{
						this.m_tweenDuaration = this.userTweenDuaration * (float)num / 20f;
					}
				}
				this.m_tweenLeftTime = this.m_tweenDuaration;
			}
		}

		private void Update()
		{
			bool flag = this.m_currentNumber != this.m_targetNumber;
			if (flag)
			{
				this.m_tweenLeftTime -= Time.deltaTime;
				bool flag2 = this.m_tweenLeftTime <= 0f;
				if (flag2)
				{
					this.m_currentNumber = this.m_targetNumber;
				}
				else
				{
					this.m_currentNumber = this.m_targetNumber - (ulong)((long)((float)this.m_deltaNumber * this.m_tweenLeftTime / this.m_tweenDuaration));
				}
				this.m_uiLabel.SetText(string.Format("{0}{1}", XSingleton<UiUtility>.singleton.NumberFormat(this.m_currentNumber), this.m_tweenPostfix));
			}
		}
	}
}