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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
|
// Author: Daniele Giardini - http://www.demigiant.com
// Created: 2015/03/27 19:02
//
// License Copyright (c) Daniele Giardini.
// This work is subject to the terms at http://dotween.demigiant.com/license.php
using UnityEngine;
using TMPro;
namespace DG.Tweening
{
/// <summary>
/// Methods that extend Text Mesh Pro objects and allow to directly create and control tweens from their instances.
/// </summary>
public static class ShortcutExtensionsTextMeshPro
{
#region Colors
/// <summary>Tweens a TextMeshPro's color to the given value.
/// Also stores the TextMeshPro as the tween's target so it can be used for filtered operations</summary>
/// <param name="endValue">The end value to reach</param><param name="duration">The duration of the tween</param>
public static Tweener DOColor(this TextMeshPro target, Color endValue, float duration)
{
return DOTween.To(() => target.color, x => target.color = x, endValue, duration)
.SetTarget(target);
}
/// <summary>Tweens a TextMeshPro's faceColor to the given value.
/// Also stores the TextMeshPro as the tween's target so it can be used for filtered operations</summary>
/// <param name="endValue">The end value to reach</param><param name="duration">The duration of the tween</param>
public static Tweener DOFaceColor(this TextMeshPro target, Color32 endValue, float duration)
{
return DOTween.To(() => target.faceColor, x => target.faceColor = x, endValue, duration)
.SetTarget(target);
}
/// <summary>Tweens a TextMeshPro's outlineColor to the given value.
/// Also stores the TextMeshPro as the tween's target so it can be used for filtered operations</summary>
/// <param name="endValue">The end value to reach</param><param name="duration">The duration of the tween</param>
public static Tweener DOOutlineColor(this TextMeshPro target, Color32 endValue, float duration)
{
return DOTween.To(() => target.outlineColor, x => target.outlineColor = x, endValue, duration)
.SetTarget(target);
}
/// <summary>Tweens a TextMeshPro's glow color to the given value.
/// Also stores the TextMeshPro as the tween's target so it can be used for filtered operations</summary>
/// <param name="endValue">The end value to reach</param><param name="duration">The duration of the tween</param>
/// <param name="useSharedMaterial">If TRUE will use the fontSharedMaterial instead than the fontMaterial</param>
public static Tweener DOGlowColor(this TextMeshPro target, Color endValue, float duration, bool useSharedMaterial = false)
{
return useSharedMaterial
? target.fontSharedMaterial.DOColor(endValue, "_GlowColor", duration).SetTarget(target)
: target.fontMaterial.DOColor(endValue, "_GlowColor", duration).SetTarget(target);
}
/// <summary>Tweens a TextMeshPro's alpha color to the given value.
/// Also stores the TextMeshPro as the tween's target so it can be used for filtered operations</summary>
/// <param name="endValue">The end value to reach</param><param name="duration">The duration of the tween</param>
public static Tweener DOFade(this TextMeshPro target, float endValue, float duration)
{
return DOTween.ToAlpha(() => target.color, x => target.color = x, endValue, duration)
.SetTarget(target);
}
/// <summary>Tweens a TextMeshPro faceColor's alpha to the given value.
/// Also stores the TextMeshPro as the tween's target so it can be used for filtered operations</summary>
/// <param name="endValue">The end value to reach</param><param name="duration">The duration of the tween</param>
public static Tweener DOFaceFade(this TextMeshPro target, float endValue, float duration)
{
return DOTween.ToAlpha(() => target.faceColor, x => target.faceColor = x, endValue, duration)
.SetTarget(target);
}
#endregion
#region Other
/// <summary>Tweens a TextMeshPro's scale to the given value (using correct uniform scale as TMP requires).
/// Also stores the TextMeshPro as the tween's target so it can be used for filtered operations</summary>
/// <param name="endValue">The end value to reach</param><param name="duration">The duration of the tween</param>
public static Tweener DOScale(this TextMeshPro target, float endValue, float duration)
{
Transform t = target.transform;
Vector3 endValueV3 = new Vector3(endValue, endValue, endValue);
return DOTween.To(() => t.localScale, x => t.localScale = x, endValueV3, duration).SetTarget(target);
}
/// <summary>Tweens a TextMeshPro's fontSize to the given value.
/// Also stores the TextMeshPro as the tween's target so it can be used for filtered operations</summary>
/// <param name="endValue">The end value to reach</param><param name="duration">The duration of the tween</param>
public static Tweener DOFontSize(this TextMeshPro target, float endValue, float duration)
{
return DOTween.To(() => target.fontSize, x => target.fontSize = x, endValue, duration)
.SetTarget(target);
}
/// <summary>Tweens a TextMeshPro's maxVisibleCharacters to the given value.
/// Also stores the TextMeshPro as the tween's target so it can be used for filtered operations</summary>
/// <param name="endValue">The end value to reach</param><param name="duration">The duration of the tween</param>
public static Tweener DOMaxVisibleCharacters(this TextMeshPro target, int endValue, float duration)
{
return DOTween.To(() => target.maxVisibleCharacters, x => target.maxVisibleCharacters = x, endValue, duration)
.SetTarget(target);
}
/// <summary>Tweens a TextMeshPro's text to the given value.
/// Also stores the TextMeshPro as the tween's target so it can be used for filtered operations</summary>
/// <param name="endValue">The end string to tween to</param><param name="duration">The duration of the tween</param>
/// <param name="richTextEnabled">If TRUE (default), rich text will be interpreted correctly while animated,
/// otherwise all tags will be considered as normal text</param>
/// <param name="scrambleMode">The type of scramble mode to use, if any</param>
/// <param name="scrambleChars">A string containing the characters to use for scrambling.
/// Use as many characters as possible (minimum 10) because DOTween uses a fast scramble mode which gives better results with more characters.
/// Leave it to NULL (default) to use default ones</param>
public static Tweener DOText(this TextMeshPro target, string endValue, float duration, bool richTextEnabled = true, ScrambleMode scrambleMode = ScrambleMode.None, string scrambleChars = null)
{
return DOTween.To(() => target.text, x => target.text = x, endValue, duration)
.SetOptions(richTextEnabled, scrambleMode, scrambleChars)
.SetTarget(target);
}
#endregion
}
/// <summary>
/// Methods that extend Text Mesh Pro objects and allow to directly create and control tweens from their instances.
/// </summary>
public static class ShortcutExtensionsTextMeshProUGUI
{
#region Colors
/// <summary>Tweens a TextMeshProUGUI's color to the given value.
/// Also stores the TextMeshProUGUI as the tween's target so it can be used for filtered operations</summary>
/// <param name="endValue">The end value to reach</param><param name="duration">The duration of the tween</param>
public static Tweener DOColor(this TextMeshProUGUI target, Color endValue, float duration)
{
return DOTween.To(() => target.color, x => target.color = x, endValue, duration)
.SetTarget(target);
}
/// <summary>Tweens a TextMeshProUGUI's faceColor to the given value.
/// Also stores the TextMeshProUGUI as the tween's target so it can be used for filtered operations</summary>
/// <param name="endValue">The end value to reach</param><param name="duration">The duration of the tween</param>
public static Tweener DOFaceColor(this TextMeshProUGUI target, Color32 endValue, float duration)
{
return DOTween.To(() => target.faceColor, x => target.faceColor = x, endValue, duration)
.SetTarget(target);
}
/// <summary>Tweens a TextMeshProUGUI's outlineColor to the given value.
/// Also stores the TextMeshProUGUI as the tween's target so it can be used for filtered operations</summary>
/// <param name="endValue">The end value to reach</param><param name="duration">The duration of the tween</param>
public static Tweener DOOutlineColor(this TextMeshProUGUI target, Color32 endValue, float duration)
{
return DOTween.To(() => target.outlineColor, x => target.outlineColor = x, endValue, duration)
.SetTarget(target);
}
/// <summary>Tweens a TextMeshProUGUI's glow color to the given value.
/// Also stores the TextMeshProUGUI as the tween's target so it can be used for filtered operations</summary>
/// <param name="endValue">The end value to reach</param><param name="duration">The duration of the tween</param>
/// <param name="useSharedMaterial">If TRUE will use the fontSharedMaterial instead than the fontMaterial</param>
public static Tweener DOGlowColor(this TextMeshProUGUI target, Color endValue, float duration, bool useSharedMaterial = false)
{
return useSharedMaterial
? target.fontSharedMaterial.DOColor(endValue, "_GlowColor", duration).SetTarget(target)
: target.fontMaterial.DOColor(endValue, "_GlowColor", duration).SetTarget(target);
}
/// <summary>Tweens a TextMeshProUGUI's alpha color to the given value.
/// Also stores the TextMeshProUGUI as the tween's target so it can be used for filtered operations</summary>
/// <param name="endValue">The end value to reach</param><param name="duration">The duration of the tween</param>
public static Tweener DOFade(this TextMeshProUGUI target, float endValue, float duration)
{
return DOTween.ToAlpha(() => target.color, x => target.color = x, endValue, duration)
.SetTarget(target);
}
/// <summary>Tweens a TextMeshProUGUI faceColor's alpha to the given value.
/// Also stores the TextMeshProUGUI as the tween's target so it can be used for filtered operations</summary>
/// <param name="endValue">The end value to reach</param><param name="duration">The duration of the tween</param>
public static Tweener DOFaceFade(this TextMeshProUGUI target, float endValue, float duration)
{
return DOTween.ToAlpha(() => target.faceColor, x => target.faceColor = x, endValue, duration)
.SetTarget(target);
}
#endregion
#region Other
/// <summary>Tweens a TextMeshProUGUI's scale to the given value (using correct uniform scale as TMP requires).
/// Also stores the TextMeshProUGUI as the tween's target so it can be used for filtered operations</summary>
/// <param name="endValue">The end value to reach</param><param name="duration">The duration of the tween</param>
public static Tweener DOScale(this TextMeshProUGUI target, float endValue, float duration)
{
Transform t = target.transform;
Vector3 endValueV3 = new Vector3(endValue, endValue, endValue);
return DOTween.To(() => t.localScale, x => t.localScale = x, endValueV3, duration).SetTarget(target);
}
/// <summary>Tweens a TextMeshProUGUI's fontSize to the given value.
/// Also stores the TextMeshProUGUI as the tween's target so it can be used for filtered operations</summary>
/// <param name="endValue">The end value to reach</param><param name="duration">The duration of the tween</param>
public static Tweener DOFontSize(this TextMeshProUGUI target, float endValue, float duration)
{
return DOTween.To(() => target.fontSize, x => target.fontSize = x, endValue, duration)
.SetTarget(target);
}
/// <summary>Tweens a TextMeshProUGUI's maxVisibleCharacters to the given value.
/// Also stores the TextMeshProUGUI as the tween's target so it can be used for filtered operations</summary>
/// <param name="endValue">The end value to reach</param><param name="duration">The duration of the tween</param>
public static Tweener DOMaxVisibleCharacters(this TextMeshProUGUI target, int endValue, float duration)
{
return DOTween.To(() => target.maxVisibleCharacters, x => target.maxVisibleCharacters = x, endValue, duration)
.SetTarget(target);
}
/// <summary>Tweens a TextMeshProUGUI's text to the given value.
/// Also stores the TextMeshProUGUI as the tween's target so it can be used for filtered operations</summary>
/// <param name="endValue">The end string to tween to</param><param name="duration">The duration of the tween</param>
/// <param name="richTextEnabled">If TRUE (default), rich text will be interpreted correctly while animated,
/// otherwise all tags will be considered as normal text</param>
/// <param name="scrambleMode">The type of scramble mode to use, if any</param>
/// <param name="scrambleChars">A string containing the characters to use for scrambling.
/// Use as many characters as possible (minimum 10) because DOTween uses a fast scramble mode which gives better results with more characters.
/// Leave it to NULL (default) to use default ones</param>
public static Tweener DOText(this TextMeshProUGUI target, string endValue, float duration, bool richTextEnabled = true, ScrambleMode scrambleMode = ScrambleMode.None, string scrambleChars = null)
{
return DOTween.To(() => target.text, x => target.text = x, endValue, duration)
.SetOptions(richTextEnabled, scrambleMode, scrambleChars)
.SetTarget(target);
}
#endregion
}
}
|