net.dreditor.chartweener 0.1.6 → 0.1.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.attestation.p7m +0 -0
- package/CharTween.asmdef +16 -16
- package/CharTween.asmdef.meta +7 -7
- package/CharTweener.ExtraTweens.cs +236 -236
- package/CharTweener.ExtraTweens.cs.meta +1 -1
- package/CharTweener.Properties.cs +446 -446
- package/CharTweener.Properties.cs.meta +13 -13
- package/CharTweener.Tweens.cs +303 -303
- package/CharTweener.Tweens.cs.meta +13 -13
- package/CharTweener.cs +747 -747
- package/CharTweener.cs.meta +13 -13
- package/CharTweenerDefaults.cs +10 -10
- package/CharTweenerDefaults.cs.meta +1 -1
- package/CharTweenerUtility.cs +26 -26
- package/CharTweenerUtility.cs.meta +13 -13
- package/LICENSE.md +20 -20
- package/LICENSE.md.meta +7 -7
- package/VertexGradientPlugin.cs +97 -97
- package/VertexGradientPlugin.cs.meta +13 -13
- package/package.json +39 -34
- package/package.json.meta +7 -7
package/CharTweener.cs
CHANGED
|
@@ -1,748 +1,748 @@
|
|
|
1
|
-
//Author: Copyright (c) 2021 Matthew Dechatech under MIT License
|
|
2
|
-
#if DOTWEEN
|
|
3
|
-
using DG.Tweening;
|
|
4
|
-
using System.Collections.Generic;
|
|
5
|
-
using TMPro;
|
|
6
|
-
using UnityEngine;
|
|
7
|
-
|
|
8
|
-
namespace CharTween
|
|
9
|
-
{
|
|
10
|
-
/// <summary>
|
|
11
|
-
///
|
|
12
|
-
/// </summary>
|
|
13
|
-
[AddComponentMenu("")]
|
|
14
|
-
public partial class CharTweener : MonoBehaviour
|
|
15
|
-
{
|
|
16
|
-
/// <summary>
|
|
17
|
-
///
|
|
18
|
-
/// </summary>
|
|
19
|
-
public TMP_Text Text { get; set; }
|
|
20
|
-
|
|
21
|
-
/// <summary>
|
|
22
|
-
///
|
|
23
|
-
/// </summary>
|
|
24
|
-
public int CharacterCount { get { return characterCount; } }
|
|
25
|
-
|
|
26
|
-
/// <summary>
|
|
27
|
-
///
|
|
28
|
-
/// </summary>
|
|
29
|
-
public float VisualUpdateInterval { get { return visualUpdateInterval; } }
|
|
30
|
-
|
|
31
|
-
// Maintain both dict and list for both fast lookup (when getting/setting properties)
|
|
32
|
-
// and fast iteration (when applying tweens)
|
|
33
|
-
private Dictionary<int, ProxyColor> proxyColorDict;
|
|
34
|
-
private List<ProxyColor> proxyColorList;
|
|
35
|
-
private Dictionary<int, ProxyTransform> proxyTransformDict;
|
|
36
|
-
private List<ProxyTransform> proxyTransformList;
|
|
37
|
-
|
|
38
|
-
private Transform proxyTransformParent;
|
|
39
|
-
private int characterCount;
|
|
40
|
-
private bool transformTweensActive;
|
|
41
|
-
private bool transformsChangedByProperties;
|
|
42
|
-
private bool colorTweensActive;
|
|
43
|
-
private bool colorsChangedByProperties;
|
|
44
|
-
private float tweenDisposeTimer;
|
|
45
|
-
private string lastValue;
|
|
46
|
-
|
|
47
|
-
private float visualUpdateInterval;
|
|
48
|
-
private float visualUpdateTimer;
|
|
49
|
-
|
|
50
|
-
/// <summary>
|
|
51
|
-
///
|
|
52
|
-
/// </summary>
|
|
53
|
-
public void Initialize(TMP_Text text)
|
|
54
|
-
{
|
|
55
|
-
Text = text;
|
|
56
|
-
Text.ForceMeshUpdate(true);
|
|
57
|
-
characterCount = text.textInfo.characterCount;
|
|
58
|
-
lastValue = Text.text;
|
|
59
|
-
TMPro_EventManager.TEXT_CHANGED_EVENT.Add(OnTextChanged);
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
/// <summary>
|
|
63
|
-
///
|
|
64
|
-
/// </summary>
|
|
65
|
-
/// <param name="updateInterval"></param>
|
|
66
|
-
public void SetVisualUpdateInterval(float updateInterval)
|
|
67
|
-
{
|
|
68
|
-
this.visualUpdateInterval = updateInterval;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
/// <summary>
|
|
72
|
-
///
|
|
73
|
-
/// </summary>
|
|
74
|
-
public void UpdateCharProperties()
|
|
75
|
-
{
|
|
76
|
-
TMP_VertexDataUpdateFlags updateFlags = 0;
|
|
77
|
-
if (transformTweensActive || transformsChangedByProperties)
|
|
78
|
-
{
|
|
79
|
-
UpdateCharPositions();
|
|
80
|
-
updateFlags |= TMP_VertexDataUpdateFlags.Vertices;
|
|
81
|
-
transformsChangedByProperties = false;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
if (colorTweensActive || colorsChangedByProperties)
|
|
85
|
-
{
|
|
86
|
-
UpdateCharColors();
|
|
87
|
-
updateFlags |= TMP_VertexDataUpdateFlags.Colors32;
|
|
88
|
-
colorsChangedByProperties = false;
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
if (updateFlags != 0)
|
|
92
|
-
Text.UpdateVertexData(updateFlags);
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
/// <summary></summary>
|
|
96
|
-
/// <param name="withCallbacks"></param>
|
|
97
|
-
public void CompleteAll(bool withCallbacks = false)
|
|
98
|
-
{
|
|
99
|
-
if (proxyTransformList != null)
|
|
100
|
-
{
|
|
101
|
-
for (var i = 0; i < proxyTransformList.Count; i++)
|
|
102
|
-
{
|
|
103
|
-
ProxyTransform proxy = proxyTransformList[i];
|
|
104
|
-
for (int j = 0; j < proxy.Tweens.Count; j++)
|
|
105
|
-
proxy.Tweens[j].Complete(withCallbacks);
|
|
106
|
-
proxy.Tweens.Clear();
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
if (proxyColorList != null)
|
|
111
|
-
{
|
|
112
|
-
for (var i = 0; i < proxyColorList.Count; i++)
|
|
113
|
-
{
|
|
114
|
-
ProxyColor proxy = proxyColorList[i];
|
|
115
|
-
for (int j = 0; j < proxy.Tweens.Count; j++)
|
|
116
|
-
proxy.Tweens[j].Complete(withCallbacks);
|
|
117
|
-
proxy.Tweens.Clear();
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
/// <summary>
|
|
123
|
-
///
|
|
124
|
-
/// </summary>
|
|
125
|
-
/// <param name="charIndex"></param>
|
|
126
|
-
/// <param name="withCallbacks"></param>
|
|
127
|
-
public void CompleteAll(int charIndex, bool withCallbacks = false)
|
|
128
|
-
{
|
|
129
|
-
ProxyColor proxyColor;
|
|
130
|
-
if (proxyColorDict != null && proxyColorDict.TryGetValue(charIndex, out proxyColor))
|
|
131
|
-
proxyColor.CompleteAll(withCallbacks);
|
|
132
|
-
|
|
133
|
-
ProxyTransform proxyTransform;
|
|
134
|
-
if (proxyTransformDict != null && proxyTransformDict.TryGetValue(charIndex, out proxyTransform))
|
|
135
|
-
proxyTransform.CompleteAll(withCallbacks);
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
/// <summary></summary>
|
|
139
|
-
/// <param name="complete"></param>
|
|
140
|
-
public void KillAll(bool complete = false)
|
|
141
|
-
{
|
|
142
|
-
if (proxyTransformList != null)
|
|
143
|
-
{
|
|
144
|
-
for (var i = 0; i < proxyTransformList.Count; i++)
|
|
145
|
-
proxyTransformList[i].KillAll(complete);
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
if (proxyColorList != null)
|
|
149
|
-
{
|
|
150
|
-
for (var i = 0; i < proxyColorList.Count; i++)
|
|
151
|
-
proxyColorList[i].KillAll(complete);
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
/// <summary>
|
|
156
|
-
///
|
|
157
|
-
/// </summary>
|
|
158
|
-
/// <param name="charIndex"></param>
|
|
159
|
-
/// <param name="complete"></param>
|
|
160
|
-
public void KillAll(int charIndex, bool complete = false)
|
|
161
|
-
{
|
|
162
|
-
ProxyColor proxyColor;
|
|
163
|
-
if (proxyColorDict != null && proxyColorDict.TryGetValue(charIndex, out proxyColor))
|
|
164
|
-
proxyColor.KillAll(complete);
|
|
165
|
-
|
|
166
|
-
ProxyTransform proxyTransform;
|
|
167
|
-
if (proxyTransformDict != null && proxyTransformDict.TryGetValue(charIndex, out proxyTransform))
|
|
168
|
-
proxyTransform.KillAll(complete);
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
/// <summary>
|
|
172
|
-
///
|
|
173
|
-
/// </summary>
|
|
174
|
-
public void DisposeInactiveTweens()
|
|
175
|
-
{
|
|
176
|
-
transformTweensActive = false;
|
|
177
|
-
if (proxyTransformList != null)
|
|
178
|
-
{
|
|
179
|
-
for (var i = proxyTransformList.Count - 1; i >= 0; i--)
|
|
180
|
-
{
|
|
181
|
-
ProxyTransform proxy = proxyTransformList[i];
|
|
182
|
-
proxy.DisposeFinishedTweens();
|
|
183
|
-
if (proxy.Tweens.Count > 0)
|
|
184
|
-
transformTweensActive = true;
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
colorTweensActive = false;
|
|
189
|
-
if (proxyColorList != null)
|
|
190
|
-
{
|
|
191
|
-
for (var i = proxyColorList.Count - 1; i >= 0; i--)
|
|
192
|
-
{
|
|
193
|
-
ProxyColor proxy = proxyColorList[i];
|
|
194
|
-
proxy.DisposeFinishedTweens();
|
|
195
|
-
if (proxy.Tweens.Count > 0)
|
|
196
|
-
colorTweensActive = true;
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
/// <summary>
|
|
202
|
-
///
|
|
203
|
-
/// </summary>
|
|
204
|
-
public void ApplyChanges()
|
|
205
|
-
{
|
|
206
|
-
UpdateCharProperties();
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
private void OnTextChanged(Object changedText)
|
|
210
|
-
{
|
|
211
|
-
if (!Text)
|
|
212
|
-
{
|
|
213
|
-
TMPro_EventManager.TEXT_CHANGED_EVENT.Remove(OnTextChanged);
|
|
214
|
-
return;
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
if (changedText == Text)
|
|
218
|
-
{
|
|
219
|
-
characterCount = Text.textInfo.characterCount;
|
|
220
|
-
if (lastValue != Text.text)
|
|
221
|
-
{
|
|
222
|
-
UpdateStartPositions();
|
|
223
|
-
lastValue = Text.text;
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
UpdateCharProperties();
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
private void NotifyActiveTransformTween()
|
|
231
|
-
{
|
|
232
|
-
transformTweensActive = true;
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
private void NotifyActiveColorTween()
|
|
236
|
-
{
|
|
237
|
-
colorTweensActive = true;
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
void Awake()
|
|
241
|
-
{
|
|
242
|
-
proxyTransformParent = new GameObject("Proxy Transforms").transform;
|
|
243
|
-
proxyTransformParent.SetParent(transform);
|
|
244
|
-
proxyTransformParent.localPosition = Vector3.zero;
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
void Update()
|
|
248
|
-
{
|
|
249
|
-
if (!Text && gameObject)
|
|
250
|
-
{
|
|
251
|
-
Destroy(this);
|
|
252
|
-
return;
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
if (!Text.enabled)
|
|
256
|
-
return;
|
|
257
|
-
|
|
258
|
-
tweenDisposeTimer += Time.deltaTime;
|
|
259
|
-
if (tweenDisposeTimer >= 1)
|
|
260
|
-
{
|
|
261
|
-
tweenDisposeTimer = 0;
|
|
262
|
-
DisposeInactiveTweens();
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
if (visualUpdateInterval > 0)
|
|
266
|
-
{
|
|
267
|
-
visualUpdateTimer += Time.deltaTime;
|
|
268
|
-
if (visualUpdateTimer >= visualUpdateInterval)
|
|
269
|
-
{
|
|
270
|
-
visualUpdateTimer = 0;
|
|
271
|
-
UpdateCharProperties();
|
|
272
|
-
}
|
|
273
|
-
}
|
|
274
|
-
else
|
|
275
|
-
{
|
|
276
|
-
UpdateCharProperties();
|
|
277
|
-
}
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
void OnDestroy()
|
|
281
|
-
{
|
|
282
|
-
TMPro_EventManager.TEXT_CHANGED_EVENT.Remove(OnTextChanged);
|
|
283
|
-
Destroy(proxyTransformParent.gameObject);
|
|
284
|
-
}
|
|
285
|
-
|
|
286
|
-
private void UpdateStartPositions()
|
|
287
|
-
{
|
|
288
|
-
if (proxyTransformDict == null)
|
|
289
|
-
return;
|
|
290
|
-
|
|
291
|
-
TMP_CharacterInfo[] charInfo = Text.textInfo.characterInfo;
|
|
292
|
-
int oldLength = lastValue.Length;
|
|
293
|
-
int newLength = Text.text.Length;
|
|
294
|
-
|
|
295
|
-
foreach (var pair in proxyTransformDict)
|
|
296
|
-
{
|
|
297
|
-
int charIndex = pair.Key;
|
|
298
|
-
ProxyTransform proxy = pair.Value;
|
|
299
|
-
|
|
300
|
-
if (charIndex >= oldLength)
|
|
301
|
-
{
|
|
302
|
-
// Character was not present in old text and is present in new text
|
|
303
|
-
if (charIndex < newLength)
|
|
304
|
-
proxy.AssignCharInfo(charInfo[pair.Key]);
|
|
305
|
-
}
|
|
306
|
-
else // pair.Key < oldLength
|
|
307
|
-
{
|
|
308
|
-
// Character was present in old text and is not present in new text
|
|
309
|
-
if (charIndex >= newLength)
|
|
310
|
-
proxy.AssignCharIndex(charIndex);
|
|
311
|
-
else
|
|
312
|
-
proxy.AssignCharInfo(charInfo[pair.Key]);
|
|
313
|
-
}
|
|
314
|
-
}
|
|
315
|
-
}
|
|
316
|
-
|
|
317
|
-
// Returns null if proxy does not exist
|
|
318
|
-
private ProxyTransform TryGetProxyTransform(int charIndex)
|
|
319
|
-
{
|
|
320
|
-
if (proxyTransformDict == null)
|
|
321
|
-
return null;
|
|
322
|
-
|
|
323
|
-
ProxyTransform proxyTransform;
|
|
324
|
-
return proxyTransformDict.TryGetValue(charIndex, out proxyTransform) ? proxyTransform : null;
|
|
325
|
-
}
|
|
326
|
-
|
|
327
|
-
// Will create proxy if does not exist
|
|
328
|
-
private ProxyTransform GetProxyTransform(int charIndex)
|
|
329
|
-
{
|
|
330
|
-
if (proxyTransformDict == null)
|
|
331
|
-
{
|
|
332
|
-
proxyTransformDict = new Dictionary<int, ProxyTransform>(CharacterCount);
|
|
333
|
-
proxyTransformList = new List<ProxyTransform>(CharacterCount);
|
|
334
|
-
}
|
|
335
|
-
|
|
336
|
-
ProxyTransform proxy;
|
|
337
|
-
if (!proxyTransformDict.TryGetValue(charIndex, out proxy))
|
|
338
|
-
{
|
|
339
|
-
Transform t = new GameObject(charIndex.ToString()).transform;
|
|
340
|
-
t.SetParent(proxyTransformParent);
|
|
341
|
-
|
|
342
|
-
proxy = charIndex >= CharacterCount
|
|
343
|
-
? new ProxyTransform(t, proxyTransformParent, charIndex)
|
|
344
|
-
: new ProxyTransform(t, proxyTransformParent, Text.textInfo.characterInfo[charIndex]);
|
|
345
|
-
proxyTransformDict.Add(charIndex, proxy);
|
|
346
|
-
proxyTransformList.Add(proxy);
|
|
347
|
-
}
|
|
348
|
-
|
|
349
|
-
return proxy;
|
|
350
|
-
}
|
|
351
|
-
|
|
352
|
-
// Returns null if proxy does not exist
|
|
353
|
-
private ProxyColor TryGetProxyColor(int charIndex)
|
|
354
|
-
{
|
|
355
|
-
if (proxyColorDict == null)
|
|
356
|
-
return null;
|
|
357
|
-
|
|
358
|
-
ProxyColor proxyColor;
|
|
359
|
-
return proxyColorDict.TryGetValue(charIndex, out proxyColor) ? proxyColor : null;
|
|
360
|
-
}
|
|
361
|
-
|
|
362
|
-
// Will create proxy if does not exist
|
|
363
|
-
private ProxyColor GetProxyColor(int charIndex)
|
|
364
|
-
{
|
|
365
|
-
if (proxyColorDict == null)
|
|
366
|
-
{
|
|
367
|
-
proxyColorDict = new Dictionary<int, ProxyColor>(CharacterCount);
|
|
368
|
-
proxyColorList = new List<ProxyColor>(CharacterCount);
|
|
369
|
-
}
|
|
370
|
-
|
|
371
|
-
ProxyColor proxy;
|
|
372
|
-
if (!proxyColorDict.TryGetValue(charIndex, out proxy))
|
|
373
|
-
{
|
|
374
|
-
proxy = new ProxyColor(Text.color, Text.colorGradient, Text.enableVertexGradient, charIndex);
|
|
375
|
-
proxyColorDict.Add(charIndex, proxy);
|
|
376
|
-
proxyColorList.Add(proxy);
|
|
377
|
-
return proxy;
|
|
378
|
-
}
|
|
379
|
-
|
|
380
|
-
return proxy;
|
|
381
|
-
}
|
|
382
|
-
|
|
383
|
-
private void UpdateCharPositions()
|
|
384
|
-
{
|
|
385
|
-
// If no transform tweens have been created then the list of proxies will not exist
|
|
386
|
-
if (proxyTransformList == null)
|
|
387
|
-
return;
|
|
388
|
-
|
|
389
|
-
for (var i = proxyTransformList.Count - 1; i >= 0; i--)
|
|
390
|
-
{
|
|
391
|
-
ProxyTransform proxy = proxyTransformList[i];
|
|
392
|
-
if (proxy.CharIndex >= characterCount)
|
|
393
|
-
continue;
|
|
394
|
-
|
|
395
|
-
int charIndex = proxy.CharIndex;
|
|
396
|
-
TMP_CharacterInfo charInfo = Text.textInfo.characterInfo[charIndex];
|
|
397
|
-
|
|
398
|
-
if (!charInfo.isVisible || !proxy.Target || !proxy.Target.hasChanged)
|
|
399
|
-
continue;
|
|
400
|
-
|
|
401
|
-
int materialIndex = charInfo.materialReferenceIndex;
|
|
402
|
-
int vertexIndex = charInfo.vertexIndex;
|
|
403
|
-
|
|
404
|
-
Vector3 origin = (charInfo.topLeft + charInfo.bottomRight) * 0.5f;
|
|
405
|
-
|
|
406
|
-
Vector3[] destinationVertices = Text.textInfo.meshInfo[materialIndex].vertices;
|
|
407
|
-
Matrix4x4 matrix = Matrix4x4.TRS(proxy.OffsetPosition, proxy.Target.localRotation, proxy.Target.localScale);
|
|
408
|
-
|
|
409
|
-
destinationVertices[vertexIndex + 1] = matrix.MultiplyPoint3x4(charInfo.topLeft - origin) + origin;
|
|
410
|
-
destinationVertices[vertexIndex + 2] = matrix.MultiplyPoint3x4(charInfo.topRight - origin) + origin;
|
|
411
|
-
destinationVertices[vertexIndex + 0] = matrix.MultiplyPoint3x4(charInfo.bottomLeft - origin) + origin;
|
|
412
|
-
destinationVertices[vertexIndex + 3] = matrix.MultiplyPoint3x4(charInfo.bottomRight - origin) + origin;
|
|
413
|
-
}
|
|
414
|
-
}
|
|
415
|
-
|
|
416
|
-
private void UpdateCharColors()
|
|
417
|
-
{
|
|
418
|
-
// If no color tweens have been created then the list of proxies will not exist
|
|
419
|
-
if (proxyColorList == null)
|
|
420
|
-
return;
|
|
421
|
-
|
|
422
|
-
for (var i = proxyColorList.Count - 1; i >= 0; i--)
|
|
423
|
-
{
|
|
424
|
-
ProxyColor proxy = proxyColorList[i];
|
|
425
|
-
if (proxy.CharIndex >= characterCount)
|
|
426
|
-
continue;
|
|
427
|
-
|
|
428
|
-
TMP_CharacterInfo charInfo = Text.textInfo.characterInfo[proxy.CharIndex];
|
|
429
|
-
if (!charInfo.isVisible || !proxy.IsModified)
|
|
430
|
-
continue;
|
|
431
|
-
|
|
432
|
-
int materialIndex = charInfo.materialReferenceIndex;
|
|
433
|
-
int vertexIndex = charInfo.vertexIndex;
|
|
434
|
-
|
|
435
|
-
Color32[] destinationColors = Text.textInfo.meshInfo[materialIndex].colors32;
|
|
436
|
-
destinationColors[vertexIndex + 1] = proxy.ColorGradient.topLeft;
|
|
437
|
-
destinationColors[vertexIndex + 2] = proxy.ColorGradient.topRight;
|
|
438
|
-
destinationColors[vertexIndex + 0] = proxy.ColorGradient.bottomLeft;
|
|
439
|
-
destinationColors[vertexIndex + 3] = proxy.ColorGradient.bottomRight;
|
|
440
|
-
}
|
|
441
|
-
}
|
|
442
|
-
|
|
443
|
-
private static Color WithAlpha(Color color, float alpha)
|
|
444
|
-
{
|
|
445
|
-
return new Color(color.r, color.g, color.b, alpha);
|
|
446
|
-
}
|
|
447
|
-
|
|
448
|
-
// Stores color data for a character. CharTweener updates vertex colors in the text mesh using this data.
|
|
449
|
-
private class ProxyColor
|
|
450
|
-
{
|
|
451
|
-
// This handles DOColorGradient
|
|
452
|
-
private static readonly VertexGradientPlugin VertexGradientPlugin = new VertexGradientPlugin();
|
|
453
|
-
|
|
454
|
-
public bool IsModified;
|
|
455
|
-
|
|
456
|
-
public VertexGradient ColorGradient; // Setting this via field will not change dirty flag
|
|
457
|
-
public bool UseColorGradient; // Setting this via field will not change dirty flag
|
|
458
|
-
public int CharIndex;
|
|
459
|
-
public Color Color { get { return GetColor(); } set { SetColor(value); } }
|
|
460
|
-
public float Alpha { get { return GetAlpha(); } set { SetAlpha(value); } }
|
|
461
|
-
|
|
462
|
-
public List<Tween> Tweens;
|
|
463
|
-
|
|
464
|
-
public ProxyColor(Color color, VertexGradient colorGradient, bool useColorGradient, int charIndex)
|
|
465
|
-
{
|
|
466
|
-
Tweens = new List<Tween>();
|
|
467
|
-
UseColorGradient = useColorGradient;
|
|
468
|
-
if (UseColorGradient)
|
|
469
|
-
ColorGradient = colorGradient;
|
|
470
|
-
else
|
|
471
|
-
Color = color;
|
|
472
|
-
CharIndex = charIndex;
|
|
473
|
-
}
|
|
474
|
-
|
|
475
|
-
public void CompleteAll(bool withCallbacks = false)
|
|
476
|
-
{
|
|
477
|
-
for (var i = 0; i < Tweens.Count; i++)
|
|
478
|
-
{
|
|
479
|
-
Tweens[i].Complete(withCallbacks);
|
|
480
|
-
}
|
|
481
|
-
}
|
|
482
|
-
|
|
483
|
-
public void KillAll(bool complete = false)
|
|
484
|
-
{
|
|
485
|
-
for (var i = 0; i < Tweens.Count; i++)
|
|
486
|
-
{
|
|
487
|
-
Tweens[i].Kill(complete);
|
|
488
|
-
}
|
|
489
|
-
}
|
|
490
|
-
|
|
491
|
-
public T AddTween<T>(T tween) where T : Tween
|
|
492
|
-
{
|
|
493
|
-
Tweens.Add(tween);
|
|
494
|
-
return tween;
|
|
495
|
-
}
|
|
496
|
-
|
|
497
|
-
public void DisposeFinishedTweens()
|
|
498
|
-
{
|
|
499
|
-
if (Tweens.Count == 0)
|
|
500
|
-
return;
|
|
501
|
-
|
|
502
|
-
for (int i = Tweens.Count - 1; i >= 0; i--)
|
|
503
|
-
{
|
|
504
|
-
Tween tween = Tweens[i];
|
|
505
|
-
if (!tween.active)
|
|
506
|
-
Tweens.RemoveAt(i);
|
|
507
|
-
}
|
|
508
|
-
}
|
|
509
|
-
|
|
510
|
-
public Tweener DOFade(float endValue, float duration)
|
|
511
|
-
{
|
|
512
|
-
IsModified = true;
|
|
513
|
-
return DOTween.To(GetAlpha, SetAlpha, endValue, duration);
|
|
514
|
-
}
|
|
515
|
-
|
|
516
|
-
public Tweener DOColor(Color endValue, float duration)
|
|
517
|
-
{
|
|
518
|
-
IsModified = true;
|
|
519
|
-
return DOTween.To(GetColor, SetColor, endValue, duration);
|
|
520
|
-
}
|
|
521
|
-
|
|
522
|
-
public Tweener DOColorGradient(VertexGradient endValue, float duration)
|
|
523
|
-
{
|
|
524
|
-
IsModified = true;
|
|
525
|
-
return DOTween.To(VertexGradientPlugin,
|
|
526
|
-
GetColorGradient, SetColorGradient,
|
|
527
|
-
endValue, duration);
|
|
528
|
-
}
|
|
529
|
-
|
|
530
|
-
public Color GetColor()
|
|
531
|
-
{
|
|
532
|
-
return ColorGradient.topLeft;
|
|
533
|
-
}
|
|
534
|
-
|
|
535
|
-
public void SetColor(Color value)
|
|
536
|
-
{
|
|
537
|
-
IsModified = true;
|
|
538
|
-
UseColorGradient = false;
|
|
539
|
-
ColorGradient.bottomLeft = value;
|
|
540
|
-
ColorGradient.topLeft = value;
|
|
541
|
-
ColorGradient.bottomRight = value;
|
|
542
|
-
ColorGradient.topRight = value;
|
|
543
|
-
}
|
|
544
|
-
|
|
545
|
-
public float GetAlpha()
|
|
546
|
-
{
|
|
547
|
-
return ColorGradient.topLeft.a;
|
|
548
|
-
}
|
|
549
|
-
|
|
550
|
-
public void SetAlpha(float value)
|
|
551
|
-
{
|
|
552
|
-
IsModified = true;
|
|
553
|
-
ColorGradient.bottomLeft = WithAlpha(ColorGradient.bottomLeft, value);
|
|
554
|
-
ColorGradient.bottomRight = WithAlpha(ColorGradient.bottomRight, value);
|
|
555
|
-
ColorGradient.topLeft = WithAlpha(ColorGradient.topLeft, value);
|
|
556
|
-
ColorGradient.topRight = WithAlpha(ColorGradient.topRight, value);
|
|
557
|
-
}
|
|
558
|
-
|
|
559
|
-
public VertexGradient GetColorGradient()
|
|
560
|
-
{
|
|
561
|
-
return ColorGradient;
|
|
562
|
-
}
|
|
563
|
-
|
|
564
|
-
public void SetColorGradient(VertexGradient value)
|
|
565
|
-
{
|
|
566
|
-
IsModified = true;
|
|
567
|
-
UseColorGradient = true;
|
|
568
|
-
ColorGradient = value;
|
|
569
|
-
}
|
|
570
|
-
}
|
|
571
|
-
|
|
572
|
-
// Stores transform data for a character. CharTweener updates vertex positions in the text mesh using this data.
|
|
573
|
-
private class ProxyTransform
|
|
574
|
-
{
|
|
575
|
-
public Transform Target { get { return target; } }
|
|
576
|
-
public int CharIndex { get { return charIndex; } }
|
|
577
|
-
public Vector3 LocalStartPosition { get { return localStartPosition; } }
|
|
578
|
-
public Vector3 StartPosition { get { return parent.TransformPoint(LocalStartPosition); } }
|
|
579
|
-
public Vector3 OffsetPosition { get { return target.localPosition; } set { target.localPosition = value; } }
|
|
580
|
-
|
|
581
|
-
public Vector3 LocalPosition
|
|
582
|
-
{
|
|
583
|
-
get { return target.localPosition + localStartPosition; }
|
|
584
|
-
set { target.localPosition = value - localStartPosition; }
|
|
585
|
-
}
|
|
586
|
-
|
|
587
|
-
public Vector3 Position
|
|
588
|
-
{
|
|
589
|
-
get { return target.position + LocalStartPosition; }
|
|
590
|
-
set { target.position = value - LocalStartPosition; }
|
|
591
|
-
}
|
|
592
|
-
|
|
593
|
-
public List<Tween> Tweens;
|
|
594
|
-
private Transform target;
|
|
595
|
-
private Transform parent;
|
|
596
|
-
private int charIndex;
|
|
597
|
-
private Vector3 localStartPosition;
|
|
598
|
-
|
|
599
|
-
public ProxyTransform(Transform target, Transform parent, int charIndex)
|
|
600
|
-
{
|
|
601
|
-
Tweens = new List<Tween>();
|
|
602
|
-
this.target = target;
|
|
603
|
-
this.parent = parent;
|
|
604
|
-
AssignCharIndex(charIndex);
|
|
605
|
-
Target.localPosition = Vector3.zero;
|
|
606
|
-
}
|
|
607
|
-
|
|
608
|
-
public ProxyTransform(Transform target, Transform parent, TMP_CharacterInfo charInfo)
|
|
609
|
-
{
|
|
610
|
-
Tweens = new List<Tween>();
|
|
611
|
-
this.target = target;
|
|
612
|
-
this.parent = parent;
|
|
613
|
-
AssignCharInfo(charInfo);
|
|
614
|
-
Target.localPosition = Vector3.zero;
|
|
615
|
-
}
|
|
616
|
-
|
|
617
|
-
public T AddTween<T>(T tween) where T : Tween
|
|
618
|
-
{
|
|
619
|
-
Tweens.Add(tween);
|
|
620
|
-
return tween;
|
|
621
|
-
}
|
|
622
|
-
|
|
623
|
-
public void CompleteAll(bool withCallbacks = false)
|
|
624
|
-
{
|
|
625
|
-
for (var i = 0; i < Tweens.Count; i++)
|
|
626
|
-
Tweens[i].Complete(withCallbacks);
|
|
627
|
-
Tweens.Clear();
|
|
628
|
-
}
|
|
629
|
-
|
|
630
|
-
public void KillAll(bool complete = false)
|
|
631
|
-
{
|
|
632
|
-
for (var i = 0; i < Tweens.Count; i++)
|
|
633
|
-
Tweens[i].Kill(complete);
|
|
634
|
-
Tweens.Clear();
|
|
635
|
-
}
|
|
636
|
-
|
|
637
|
-
public void DisposeFinishedTweens()
|
|
638
|
-
{
|
|
639
|
-
if (Tweens.Count == 0)
|
|
640
|
-
return;
|
|
641
|
-
|
|
642
|
-
for (int i = Tweens.Count - 1; i >= 0; i--)
|
|
643
|
-
{
|
|
644
|
-
Tween tween = Tweens[i];
|
|
645
|
-
if (!tween.active)
|
|
646
|
-
Tweens.RemoveAt(i);
|
|
647
|
-
}
|
|
648
|
-
}
|
|
649
|
-
|
|
650
|
-
public void AssignCharInfo(TMP_CharacterInfo charInfo)
|
|
651
|
-
{
|
|
652
|
-
charIndex = charInfo.index;
|
|
653
|
-
if (charInfo.isVisible)
|
|
654
|
-
{
|
|
655
|
-
localStartPosition = new Vector3(
|
|
656
|
-
(charInfo.topLeft.x + charInfo.bottomRight.x) * 0.5f,
|
|
657
|
-
(charInfo.topLeft.y + charInfo.bottomRight.y) * 0.5f,
|
|
658
|
-
(charInfo.topLeft.z + charInfo.bottomRight.z) * 0.5f
|
|
659
|
-
);
|
|
660
|
-
}
|
|
661
|
-
else
|
|
662
|
-
{
|
|
663
|
-
localStartPosition = Vector3.zero;
|
|
664
|
-
}
|
|
665
|
-
}
|
|
666
|
-
|
|
667
|
-
public void AssignCharIndex(int charIndex)
|
|
668
|
-
{
|
|
669
|
-
this.charIndex = charIndex;
|
|
670
|
-
localStartPosition = Vector3.zero;
|
|
671
|
-
}
|
|
672
|
-
|
|
673
|
-
public Tweener DOMove(Vector3 endValue, float duration, bool snapping = false)
|
|
674
|
-
{
|
|
675
|
-
return snapping
|
|
676
|
-
? DOTween.To(GetPosition, SetPositionAndSnap, endValue, duration).SetTarget(target)
|
|
677
|
-
: DOTween.To(GetPosition, SetPosition, endValue, duration).SetTarget(target);
|
|
678
|
-
}
|
|
679
|
-
|
|
680
|
-
public Tweener DOMoveX(float endValue, float duration, bool snapping = false)
|
|
681
|
-
{
|
|
682
|
-
return snapping
|
|
683
|
-
? DOTween.ToAxis(GetPosition, SetPositionAndSnap, endValue, duration, AxisConstraint.X).SetTarget(target)
|
|
684
|
-
: DOTween.ToAxis(GetPosition, SetPosition, endValue, duration, AxisConstraint.X).SetTarget(target);
|
|
685
|
-
}
|
|
686
|
-
|
|
687
|
-
public Tweener DOMoveY(float endValue, float duration, bool snapping = false)
|
|
688
|
-
{
|
|
689
|
-
return snapping
|
|
690
|
-
? DOTween.ToAxis(GetPosition, SetPositionAndSnap, endValue, duration, AxisConstraint.Y).SetTarget(target)
|
|
691
|
-
: DOTween.ToAxis(GetPosition, SetPosition, endValue, duration, AxisConstraint.Y).SetTarget(target);
|
|
692
|
-
}
|
|
693
|
-
|
|
694
|
-
public Tweener DOMoveZ(float endValue, float duration, bool snapping = false)
|
|
695
|
-
{
|
|
696
|
-
return snapping
|
|
697
|
-
? DOTween.ToAxis(GetPosition, SetPositionAndSnap, endValue, duration, AxisConstraint.Z).SetTarget(target)
|
|
698
|
-
: DOTween.ToAxis(GetPosition, SetPosition, endValue, duration, AxisConstraint.Z).SetTarget(target);
|
|
699
|
-
}
|
|
700
|
-
|
|
701
|
-
public Tweener DOLocalMove(Vector3 endValue, float duration, bool snapping = false)
|
|
702
|
-
{
|
|
703
|
-
return snapping
|
|
704
|
-
? DOTween.To(GetLocalPosition, SetLocalPositionAndSnap, endValue, duration).SetTarget(target)
|
|
705
|
-
: DOTween.To(GetLocalPosition, SetLocalPosition, endValue, duration).SetTarget(target);
|
|
706
|
-
}
|
|
707
|
-
|
|
708
|
-
public Tweener DOLocalMoveX(float endValue, float duration, bool snapping = false)
|
|
709
|
-
{
|
|
710
|
-
return snapping
|
|
711
|
-
? DOTween.ToAxis(GetLocalPosition, SetLocalPositionAndSnap, endValue, duration, AxisConstraint.X).SetTarget(target)
|
|
712
|
-
: DOTween.ToAxis(GetLocalPosition, SetLocalPosition, endValue, duration, AxisConstraint.X).SetTarget(target);
|
|
713
|
-
}
|
|
714
|
-
|
|
715
|
-
public Tweener DOLocalMoveY(float endValue, float duration, bool snapping = false)
|
|
716
|
-
{
|
|
717
|
-
return snapping
|
|
718
|
-
? DOTween.ToAxis(GetLocalPosition, SetLocalPositionAndSnap, endValue, duration, AxisConstraint.Y).SetTarget(target)
|
|
719
|
-
: DOTween.ToAxis(GetLocalPosition, SetLocalPosition, endValue, duration, AxisConstraint.Y).SetTarget(target);
|
|
720
|
-
}
|
|
721
|
-
|
|
722
|
-
public Tweener DOLocalMoveZ(float endValue, float duration, bool snapping = false)
|
|
723
|
-
{
|
|
724
|
-
return snapping
|
|
725
|
-
? DOTween.ToAxis(GetLocalPosition, SetLocalPositionAndSnap, endValue, duration, AxisConstraint.Z).SetTarget(target)
|
|
726
|
-
: DOTween.ToAxis(GetLocalPosition, SetLocalPosition, endValue, duration, AxisConstraint.Z).SetTarget(target);
|
|
727
|
-
}
|
|
728
|
-
|
|
729
|
-
// These getters and setters are for use with DOTween.To
|
|
730
|
-
public Vector3 GetLocalPosition() { return LocalPosition; }
|
|
731
|
-
public void SetLocalPosition(Vector3 value) { LocalPosition = value; }
|
|
732
|
-
|
|
733
|
-
public void SetLocalPositionAndSnap(Vector3 value)
|
|
734
|
-
{
|
|
735
|
-
LocalPosition = new Vector3(Mathf.Round(value.x), Mathf.Round(value.y), Mathf.Round(value.z));
|
|
736
|
-
}
|
|
737
|
-
|
|
738
|
-
public Vector3 GetPosition() { return Position; }
|
|
739
|
-
public void SetPosition(Vector3 value) { Position = value; }
|
|
740
|
-
|
|
741
|
-
public void SetPositionAndSnap(Vector3 value)
|
|
742
|
-
{
|
|
743
|
-
Position = new Vector3(Mathf.Round(value.x), Mathf.Round(value.y), Mathf.Round(value.z));
|
|
744
|
-
}
|
|
745
|
-
}
|
|
746
|
-
}
|
|
747
|
-
}
|
|
1
|
+
//Author: Copyright (c) 2021 Matthew Dechatech under MIT License
|
|
2
|
+
#if DOTWEEN
|
|
3
|
+
using DG.Tweening;
|
|
4
|
+
using System.Collections.Generic;
|
|
5
|
+
using TMPro;
|
|
6
|
+
using UnityEngine;
|
|
7
|
+
|
|
8
|
+
namespace CharTween
|
|
9
|
+
{
|
|
10
|
+
/// <summary>
|
|
11
|
+
///
|
|
12
|
+
/// </summary>
|
|
13
|
+
[AddComponentMenu("")]
|
|
14
|
+
public partial class CharTweener : MonoBehaviour
|
|
15
|
+
{
|
|
16
|
+
/// <summary>
|
|
17
|
+
///
|
|
18
|
+
/// </summary>
|
|
19
|
+
public TMP_Text Text { get; set; }
|
|
20
|
+
|
|
21
|
+
/// <summary>
|
|
22
|
+
///
|
|
23
|
+
/// </summary>
|
|
24
|
+
public int CharacterCount { get { return characterCount; } }
|
|
25
|
+
|
|
26
|
+
/// <summary>
|
|
27
|
+
///
|
|
28
|
+
/// </summary>
|
|
29
|
+
public float VisualUpdateInterval { get { return visualUpdateInterval; } }
|
|
30
|
+
|
|
31
|
+
// Maintain both dict and list for both fast lookup (when getting/setting properties)
|
|
32
|
+
// and fast iteration (when applying tweens)
|
|
33
|
+
private Dictionary<int, ProxyColor> proxyColorDict;
|
|
34
|
+
private List<ProxyColor> proxyColorList;
|
|
35
|
+
private Dictionary<int, ProxyTransform> proxyTransformDict;
|
|
36
|
+
private List<ProxyTransform> proxyTransformList;
|
|
37
|
+
|
|
38
|
+
private Transform proxyTransformParent;
|
|
39
|
+
private int characterCount;
|
|
40
|
+
private bool transformTweensActive;
|
|
41
|
+
private bool transformsChangedByProperties;
|
|
42
|
+
private bool colorTweensActive;
|
|
43
|
+
private bool colorsChangedByProperties;
|
|
44
|
+
private float tweenDisposeTimer;
|
|
45
|
+
private string lastValue;
|
|
46
|
+
|
|
47
|
+
private float visualUpdateInterval;
|
|
48
|
+
private float visualUpdateTimer;
|
|
49
|
+
|
|
50
|
+
/// <summary>
|
|
51
|
+
///
|
|
52
|
+
/// </summary>
|
|
53
|
+
public void Initialize(TMP_Text text)
|
|
54
|
+
{
|
|
55
|
+
Text = text;
|
|
56
|
+
Text.ForceMeshUpdate(true);
|
|
57
|
+
characterCount = text.textInfo.characterCount;
|
|
58
|
+
lastValue = Text.text;
|
|
59
|
+
TMPro_EventManager.TEXT_CHANGED_EVENT.Add(OnTextChanged);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/// <summary>
|
|
63
|
+
///
|
|
64
|
+
/// </summary>
|
|
65
|
+
/// <param name="updateInterval"></param>
|
|
66
|
+
public void SetVisualUpdateInterval(float updateInterval)
|
|
67
|
+
{
|
|
68
|
+
this.visualUpdateInterval = updateInterval;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/// <summary>
|
|
72
|
+
///
|
|
73
|
+
/// </summary>
|
|
74
|
+
public void UpdateCharProperties()
|
|
75
|
+
{
|
|
76
|
+
TMP_VertexDataUpdateFlags updateFlags = 0;
|
|
77
|
+
if (transformTweensActive || transformsChangedByProperties)
|
|
78
|
+
{
|
|
79
|
+
UpdateCharPositions();
|
|
80
|
+
updateFlags |= TMP_VertexDataUpdateFlags.Vertices;
|
|
81
|
+
transformsChangedByProperties = false;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
if (colorTweensActive || colorsChangedByProperties)
|
|
85
|
+
{
|
|
86
|
+
UpdateCharColors();
|
|
87
|
+
updateFlags |= TMP_VertexDataUpdateFlags.Colors32;
|
|
88
|
+
colorsChangedByProperties = false;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
if (updateFlags != 0)
|
|
92
|
+
Text.UpdateVertexData(updateFlags);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/// <summary></summary>
|
|
96
|
+
/// <param name="withCallbacks"></param>
|
|
97
|
+
public void CompleteAll(bool withCallbacks = false)
|
|
98
|
+
{
|
|
99
|
+
if (proxyTransformList != null)
|
|
100
|
+
{
|
|
101
|
+
for (var i = 0; i < proxyTransformList.Count; i++)
|
|
102
|
+
{
|
|
103
|
+
ProxyTransform proxy = proxyTransformList[i];
|
|
104
|
+
for (int j = 0; j < proxy.Tweens.Count; j++)
|
|
105
|
+
proxy.Tweens[j].Complete(withCallbacks);
|
|
106
|
+
proxy.Tweens.Clear();
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
if (proxyColorList != null)
|
|
111
|
+
{
|
|
112
|
+
for (var i = 0; i < proxyColorList.Count; i++)
|
|
113
|
+
{
|
|
114
|
+
ProxyColor proxy = proxyColorList[i];
|
|
115
|
+
for (int j = 0; j < proxy.Tweens.Count; j++)
|
|
116
|
+
proxy.Tweens[j].Complete(withCallbacks);
|
|
117
|
+
proxy.Tweens.Clear();
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/// <summary>
|
|
123
|
+
///
|
|
124
|
+
/// </summary>
|
|
125
|
+
/// <param name="charIndex"></param>
|
|
126
|
+
/// <param name="withCallbacks"></param>
|
|
127
|
+
public void CompleteAll(int charIndex, bool withCallbacks = false)
|
|
128
|
+
{
|
|
129
|
+
ProxyColor proxyColor;
|
|
130
|
+
if (proxyColorDict != null && proxyColorDict.TryGetValue(charIndex, out proxyColor))
|
|
131
|
+
proxyColor.CompleteAll(withCallbacks);
|
|
132
|
+
|
|
133
|
+
ProxyTransform proxyTransform;
|
|
134
|
+
if (proxyTransformDict != null && proxyTransformDict.TryGetValue(charIndex, out proxyTransform))
|
|
135
|
+
proxyTransform.CompleteAll(withCallbacks);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/// <summary></summary>
|
|
139
|
+
/// <param name="complete"></param>
|
|
140
|
+
public void KillAll(bool complete = false)
|
|
141
|
+
{
|
|
142
|
+
if (proxyTransformList != null)
|
|
143
|
+
{
|
|
144
|
+
for (var i = 0; i < proxyTransformList.Count; i++)
|
|
145
|
+
proxyTransformList[i].KillAll(complete);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
if (proxyColorList != null)
|
|
149
|
+
{
|
|
150
|
+
for (var i = 0; i < proxyColorList.Count; i++)
|
|
151
|
+
proxyColorList[i].KillAll(complete);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/// <summary>
|
|
156
|
+
///
|
|
157
|
+
/// </summary>
|
|
158
|
+
/// <param name="charIndex"></param>
|
|
159
|
+
/// <param name="complete"></param>
|
|
160
|
+
public void KillAll(int charIndex, bool complete = false)
|
|
161
|
+
{
|
|
162
|
+
ProxyColor proxyColor;
|
|
163
|
+
if (proxyColorDict != null && proxyColorDict.TryGetValue(charIndex, out proxyColor))
|
|
164
|
+
proxyColor.KillAll(complete);
|
|
165
|
+
|
|
166
|
+
ProxyTransform proxyTransform;
|
|
167
|
+
if (proxyTransformDict != null && proxyTransformDict.TryGetValue(charIndex, out proxyTransform))
|
|
168
|
+
proxyTransform.KillAll(complete);
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/// <summary>
|
|
172
|
+
///
|
|
173
|
+
/// </summary>
|
|
174
|
+
public void DisposeInactiveTweens()
|
|
175
|
+
{
|
|
176
|
+
transformTweensActive = false;
|
|
177
|
+
if (proxyTransformList != null)
|
|
178
|
+
{
|
|
179
|
+
for (var i = proxyTransformList.Count - 1; i >= 0; i--)
|
|
180
|
+
{
|
|
181
|
+
ProxyTransform proxy = proxyTransformList[i];
|
|
182
|
+
proxy.DisposeFinishedTweens();
|
|
183
|
+
if (proxy.Tweens.Count > 0)
|
|
184
|
+
transformTweensActive = true;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
colorTweensActive = false;
|
|
189
|
+
if (proxyColorList != null)
|
|
190
|
+
{
|
|
191
|
+
for (var i = proxyColorList.Count - 1; i >= 0; i--)
|
|
192
|
+
{
|
|
193
|
+
ProxyColor proxy = proxyColorList[i];
|
|
194
|
+
proxy.DisposeFinishedTweens();
|
|
195
|
+
if (proxy.Tweens.Count > 0)
|
|
196
|
+
colorTweensActive = true;
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
/// <summary>
|
|
202
|
+
///
|
|
203
|
+
/// </summary>
|
|
204
|
+
public void ApplyChanges()
|
|
205
|
+
{
|
|
206
|
+
UpdateCharProperties();
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
private void OnTextChanged(Object changedText)
|
|
210
|
+
{
|
|
211
|
+
if (!Text)
|
|
212
|
+
{
|
|
213
|
+
TMPro_EventManager.TEXT_CHANGED_EVENT.Remove(OnTextChanged);
|
|
214
|
+
return;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
if (changedText == Text)
|
|
218
|
+
{
|
|
219
|
+
characterCount = Text.textInfo.characterCount;
|
|
220
|
+
if (lastValue != Text.text)
|
|
221
|
+
{
|
|
222
|
+
UpdateStartPositions();
|
|
223
|
+
lastValue = Text.text;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
UpdateCharProperties();
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
private void NotifyActiveTransformTween()
|
|
231
|
+
{
|
|
232
|
+
transformTweensActive = true;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
private void NotifyActiveColorTween()
|
|
236
|
+
{
|
|
237
|
+
colorTweensActive = true;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
void Awake()
|
|
241
|
+
{
|
|
242
|
+
proxyTransformParent = new GameObject("Proxy Transforms").transform;
|
|
243
|
+
proxyTransformParent.SetParent(transform);
|
|
244
|
+
proxyTransformParent.localPosition = Vector3.zero;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
void Update()
|
|
248
|
+
{
|
|
249
|
+
if (!Text && gameObject)
|
|
250
|
+
{
|
|
251
|
+
Destroy(this);
|
|
252
|
+
return;
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
if (!Text.enabled)
|
|
256
|
+
return;
|
|
257
|
+
|
|
258
|
+
tweenDisposeTimer += Time.deltaTime;
|
|
259
|
+
if (tweenDisposeTimer >= 1)
|
|
260
|
+
{
|
|
261
|
+
tweenDisposeTimer = 0;
|
|
262
|
+
DisposeInactiveTweens();
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
if (visualUpdateInterval > 0)
|
|
266
|
+
{
|
|
267
|
+
visualUpdateTimer += Time.deltaTime;
|
|
268
|
+
if (visualUpdateTimer >= visualUpdateInterval)
|
|
269
|
+
{
|
|
270
|
+
visualUpdateTimer = 0;
|
|
271
|
+
UpdateCharProperties();
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
else
|
|
275
|
+
{
|
|
276
|
+
UpdateCharProperties();
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
void OnDestroy()
|
|
281
|
+
{
|
|
282
|
+
TMPro_EventManager.TEXT_CHANGED_EVENT.Remove(OnTextChanged);
|
|
283
|
+
Destroy(proxyTransformParent.gameObject);
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
private void UpdateStartPositions()
|
|
287
|
+
{
|
|
288
|
+
if (proxyTransformDict == null)
|
|
289
|
+
return;
|
|
290
|
+
|
|
291
|
+
TMP_CharacterInfo[] charInfo = Text.textInfo.characterInfo;
|
|
292
|
+
int oldLength = lastValue.Length;
|
|
293
|
+
int newLength = Text.text.Length;
|
|
294
|
+
|
|
295
|
+
foreach (var pair in proxyTransformDict)
|
|
296
|
+
{
|
|
297
|
+
int charIndex = pair.Key;
|
|
298
|
+
ProxyTransform proxy = pair.Value;
|
|
299
|
+
|
|
300
|
+
if (charIndex >= oldLength)
|
|
301
|
+
{
|
|
302
|
+
// Character was not present in old text and is present in new text
|
|
303
|
+
if (charIndex < newLength)
|
|
304
|
+
proxy.AssignCharInfo(charInfo[pair.Key]);
|
|
305
|
+
}
|
|
306
|
+
else // pair.Key < oldLength
|
|
307
|
+
{
|
|
308
|
+
// Character was present in old text and is not present in new text
|
|
309
|
+
if (charIndex >= newLength)
|
|
310
|
+
proxy.AssignCharIndex(charIndex);
|
|
311
|
+
else
|
|
312
|
+
proxy.AssignCharInfo(charInfo[pair.Key]);
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
// Returns null if proxy does not exist
|
|
318
|
+
private ProxyTransform TryGetProxyTransform(int charIndex)
|
|
319
|
+
{
|
|
320
|
+
if (proxyTransformDict == null)
|
|
321
|
+
return null;
|
|
322
|
+
|
|
323
|
+
ProxyTransform proxyTransform;
|
|
324
|
+
return proxyTransformDict.TryGetValue(charIndex, out proxyTransform) ? proxyTransform : null;
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
// Will create proxy if does not exist
|
|
328
|
+
private ProxyTransform GetProxyTransform(int charIndex)
|
|
329
|
+
{
|
|
330
|
+
if (proxyTransformDict == null)
|
|
331
|
+
{
|
|
332
|
+
proxyTransformDict = new Dictionary<int, ProxyTransform>(CharacterCount);
|
|
333
|
+
proxyTransformList = new List<ProxyTransform>(CharacterCount);
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
ProxyTransform proxy;
|
|
337
|
+
if (!proxyTransformDict.TryGetValue(charIndex, out proxy))
|
|
338
|
+
{
|
|
339
|
+
Transform t = new GameObject(charIndex.ToString()).transform;
|
|
340
|
+
t.SetParent(proxyTransformParent);
|
|
341
|
+
|
|
342
|
+
proxy = charIndex >= CharacterCount
|
|
343
|
+
? new ProxyTransform(t, proxyTransformParent, charIndex)
|
|
344
|
+
: new ProxyTransform(t, proxyTransformParent, Text.textInfo.characterInfo[charIndex]);
|
|
345
|
+
proxyTransformDict.Add(charIndex, proxy);
|
|
346
|
+
proxyTransformList.Add(proxy);
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
return proxy;
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
// Returns null if proxy does not exist
|
|
353
|
+
private ProxyColor TryGetProxyColor(int charIndex)
|
|
354
|
+
{
|
|
355
|
+
if (proxyColorDict == null)
|
|
356
|
+
return null;
|
|
357
|
+
|
|
358
|
+
ProxyColor proxyColor;
|
|
359
|
+
return proxyColorDict.TryGetValue(charIndex, out proxyColor) ? proxyColor : null;
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
// Will create proxy if does not exist
|
|
363
|
+
private ProxyColor GetProxyColor(int charIndex)
|
|
364
|
+
{
|
|
365
|
+
if (proxyColorDict == null)
|
|
366
|
+
{
|
|
367
|
+
proxyColorDict = new Dictionary<int, ProxyColor>(CharacterCount);
|
|
368
|
+
proxyColorList = new List<ProxyColor>(CharacterCount);
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
ProxyColor proxy;
|
|
372
|
+
if (!proxyColorDict.TryGetValue(charIndex, out proxy))
|
|
373
|
+
{
|
|
374
|
+
proxy = new ProxyColor(Text.color, Text.colorGradient, Text.enableVertexGradient, charIndex);
|
|
375
|
+
proxyColorDict.Add(charIndex, proxy);
|
|
376
|
+
proxyColorList.Add(proxy);
|
|
377
|
+
return proxy;
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
return proxy;
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
private void UpdateCharPositions()
|
|
384
|
+
{
|
|
385
|
+
// If no transform tweens have been created then the list of proxies will not exist
|
|
386
|
+
if (proxyTransformList == null)
|
|
387
|
+
return;
|
|
388
|
+
|
|
389
|
+
for (var i = proxyTransformList.Count - 1; i >= 0; i--)
|
|
390
|
+
{
|
|
391
|
+
ProxyTransform proxy = proxyTransformList[i];
|
|
392
|
+
if (proxy.CharIndex >= characterCount)
|
|
393
|
+
continue;
|
|
394
|
+
|
|
395
|
+
int charIndex = proxy.CharIndex;
|
|
396
|
+
TMP_CharacterInfo charInfo = Text.textInfo.characterInfo[charIndex];
|
|
397
|
+
|
|
398
|
+
if (!charInfo.isVisible || !proxy.Target || !proxy.Target.hasChanged)
|
|
399
|
+
continue;
|
|
400
|
+
|
|
401
|
+
int materialIndex = charInfo.materialReferenceIndex;
|
|
402
|
+
int vertexIndex = charInfo.vertexIndex;
|
|
403
|
+
|
|
404
|
+
Vector3 origin = (charInfo.topLeft + charInfo.bottomRight) * 0.5f;
|
|
405
|
+
|
|
406
|
+
Vector3[] destinationVertices = Text.textInfo.meshInfo[materialIndex].vertices;
|
|
407
|
+
Matrix4x4 matrix = Matrix4x4.TRS(proxy.OffsetPosition, proxy.Target.localRotation, proxy.Target.localScale);
|
|
408
|
+
|
|
409
|
+
destinationVertices[vertexIndex + 1] = matrix.MultiplyPoint3x4(charInfo.topLeft - origin) + origin;
|
|
410
|
+
destinationVertices[vertexIndex + 2] = matrix.MultiplyPoint3x4(charInfo.topRight - origin) + origin;
|
|
411
|
+
destinationVertices[vertexIndex + 0] = matrix.MultiplyPoint3x4(charInfo.bottomLeft - origin) + origin;
|
|
412
|
+
destinationVertices[vertexIndex + 3] = matrix.MultiplyPoint3x4(charInfo.bottomRight - origin) + origin;
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
private void UpdateCharColors()
|
|
417
|
+
{
|
|
418
|
+
// If no color tweens have been created then the list of proxies will not exist
|
|
419
|
+
if (proxyColorList == null)
|
|
420
|
+
return;
|
|
421
|
+
|
|
422
|
+
for (var i = proxyColorList.Count - 1; i >= 0; i--)
|
|
423
|
+
{
|
|
424
|
+
ProxyColor proxy = proxyColorList[i];
|
|
425
|
+
if (proxy.CharIndex >= characterCount)
|
|
426
|
+
continue;
|
|
427
|
+
|
|
428
|
+
TMP_CharacterInfo charInfo = Text.textInfo.characterInfo[proxy.CharIndex];
|
|
429
|
+
if (!charInfo.isVisible || !proxy.IsModified)
|
|
430
|
+
continue;
|
|
431
|
+
|
|
432
|
+
int materialIndex = charInfo.materialReferenceIndex;
|
|
433
|
+
int vertexIndex = charInfo.vertexIndex;
|
|
434
|
+
|
|
435
|
+
Color32[] destinationColors = Text.textInfo.meshInfo[materialIndex].colors32;
|
|
436
|
+
destinationColors[vertexIndex + 1] = proxy.ColorGradient.topLeft;
|
|
437
|
+
destinationColors[vertexIndex + 2] = proxy.ColorGradient.topRight;
|
|
438
|
+
destinationColors[vertexIndex + 0] = proxy.ColorGradient.bottomLeft;
|
|
439
|
+
destinationColors[vertexIndex + 3] = proxy.ColorGradient.bottomRight;
|
|
440
|
+
}
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
private static Color WithAlpha(Color color, float alpha)
|
|
444
|
+
{
|
|
445
|
+
return new Color(color.r, color.g, color.b, alpha);
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
// Stores color data for a character. CharTweener updates vertex colors in the text mesh using this data.
|
|
449
|
+
private class ProxyColor
|
|
450
|
+
{
|
|
451
|
+
// This handles DOColorGradient
|
|
452
|
+
private static readonly VertexGradientPlugin VertexGradientPlugin = new VertexGradientPlugin();
|
|
453
|
+
|
|
454
|
+
public bool IsModified;
|
|
455
|
+
|
|
456
|
+
public VertexGradient ColorGradient; // Setting this via field will not change dirty flag
|
|
457
|
+
public bool UseColorGradient; // Setting this via field will not change dirty flag
|
|
458
|
+
public int CharIndex;
|
|
459
|
+
public Color Color { get { return GetColor(); } set { SetColor(value); } }
|
|
460
|
+
public float Alpha { get { return GetAlpha(); } set { SetAlpha(value); } }
|
|
461
|
+
|
|
462
|
+
public List<Tween> Tweens;
|
|
463
|
+
|
|
464
|
+
public ProxyColor(Color color, VertexGradient colorGradient, bool useColorGradient, int charIndex)
|
|
465
|
+
{
|
|
466
|
+
Tweens = new List<Tween>();
|
|
467
|
+
UseColorGradient = useColorGradient;
|
|
468
|
+
if (UseColorGradient)
|
|
469
|
+
ColorGradient = colorGradient;
|
|
470
|
+
else
|
|
471
|
+
Color = color;
|
|
472
|
+
CharIndex = charIndex;
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
public void CompleteAll(bool withCallbacks = false)
|
|
476
|
+
{
|
|
477
|
+
for (var i = 0; i < Tweens.Count; i++)
|
|
478
|
+
{
|
|
479
|
+
Tweens[i].Complete(withCallbacks);
|
|
480
|
+
}
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
public void KillAll(bool complete = false)
|
|
484
|
+
{
|
|
485
|
+
for (var i = 0; i < Tweens.Count; i++)
|
|
486
|
+
{
|
|
487
|
+
Tweens[i].Kill(complete);
|
|
488
|
+
}
|
|
489
|
+
}
|
|
490
|
+
|
|
491
|
+
public T AddTween<T>(T tween) where T : Tween
|
|
492
|
+
{
|
|
493
|
+
Tweens.Add(tween);
|
|
494
|
+
return tween;
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
public void DisposeFinishedTweens()
|
|
498
|
+
{
|
|
499
|
+
if (Tweens.Count == 0)
|
|
500
|
+
return;
|
|
501
|
+
|
|
502
|
+
for (int i = Tweens.Count - 1; i >= 0; i--)
|
|
503
|
+
{
|
|
504
|
+
Tween tween = Tweens[i];
|
|
505
|
+
if (!tween.active)
|
|
506
|
+
Tweens.RemoveAt(i);
|
|
507
|
+
}
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
public Tweener DOFade(float endValue, float duration)
|
|
511
|
+
{
|
|
512
|
+
IsModified = true;
|
|
513
|
+
return DOTween.To(GetAlpha, SetAlpha, endValue, duration);
|
|
514
|
+
}
|
|
515
|
+
|
|
516
|
+
public Tweener DOColor(Color endValue, float duration)
|
|
517
|
+
{
|
|
518
|
+
IsModified = true;
|
|
519
|
+
return DOTween.To(GetColor, SetColor, endValue, duration);
|
|
520
|
+
}
|
|
521
|
+
|
|
522
|
+
public Tweener DOColorGradient(VertexGradient endValue, float duration)
|
|
523
|
+
{
|
|
524
|
+
IsModified = true;
|
|
525
|
+
return DOTween.To(VertexGradientPlugin,
|
|
526
|
+
GetColorGradient, SetColorGradient,
|
|
527
|
+
endValue, duration);
|
|
528
|
+
}
|
|
529
|
+
|
|
530
|
+
public Color GetColor()
|
|
531
|
+
{
|
|
532
|
+
return ColorGradient.topLeft;
|
|
533
|
+
}
|
|
534
|
+
|
|
535
|
+
public void SetColor(Color value)
|
|
536
|
+
{
|
|
537
|
+
IsModified = true;
|
|
538
|
+
UseColorGradient = false;
|
|
539
|
+
ColorGradient.bottomLeft = value;
|
|
540
|
+
ColorGradient.topLeft = value;
|
|
541
|
+
ColorGradient.bottomRight = value;
|
|
542
|
+
ColorGradient.topRight = value;
|
|
543
|
+
}
|
|
544
|
+
|
|
545
|
+
public float GetAlpha()
|
|
546
|
+
{
|
|
547
|
+
return ColorGradient.topLeft.a;
|
|
548
|
+
}
|
|
549
|
+
|
|
550
|
+
public void SetAlpha(float value)
|
|
551
|
+
{
|
|
552
|
+
IsModified = true;
|
|
553
|
+
ColorGradient.bottomLeft = WithAlpha(ColorGradient.bottomLeft, value);
|
|
554
|
+
ColorGradient.bottomRight = WithAlpha(ColorGradient.bottomRight, value);
|
|
555
|
+
ColorGradient.topLeft = WithAlpha(ColorGradient.topLeft, value);
|
|
556
|
+
ColorGradient.topRight = WithAlpha(ColorGradient.topRight, value);
|
|
557
|
+
}
|
|
558
|
+
|
|
559
|
+
public VertexGradient GetColorGradient()
|
|
560
|
+
{
|
|
561
|
+
return ColorGradient;
|
|
562
|
+
}
|
|
563
|
+
|
|
564
|
+
public void SetColorGradient(VertexGradient value)
|
|
565
|
+
{
|
|
566
|
+
IsModified = true;
|
|
567
|
+
UseColorGradient = true;
|
|
568
|
+
ColorGradient = value;
|
|
569
|
+
}
|
|
570
|
+
}
|
|
571
|
+
|
|
572
|
+
// Stores transform data for a character. CharTweener updates vertex positions in the text mesh using this data.
|
|
573
|
+
private class ProxyTransform
|
|
574
|
+
{
|
|
575
|
+
public Transform Target { get { return target; } }
|
|
576
|
+
public int CharIndex { get { return charIndex; } }
|
|
577
|
+
public Vector3 LocalStartPosition { get { return localStartPosition; } }
|
|
578
|
+
public Vector3 StartPosition { get { return parent.TransformPoint(LocalStartPosition); } }
|
|
579
|
+
public Vector3 OffsetPosition { get { return target.localPosition; } set { target.localPosition = value; } }
|
|
580
|
+
|
|
581
|
+
public Vector3 LocalPosition
|
|
582
|
+
{
|
|
583
|
+
get { return target.localPosition + localStartPosition; }
|
|
584
|
+
set { target.localPosition = value - localStartPosition; }
|
|
585
|
+
}
|
|
586
|
+
|
|
587
|
+
public Vector3 Position
|
|
588
|
+
{
|
|
589
|
+
get { return target.position + LocalStartPosition; }
|
|
590
|
+
set { target.position = value - LocalStartPosition; }
|
|
591
|
+
}
|
|
592
|
+
|
|
593
|
+
public List<Tween> Tweens;
|
|
594
|
+
private Transform target;
|
|
595
|
+
private Transform parent;
|
|
596
|
+
private int charIndex;
|
|
597
|
+
private Vector3 localStartPosition;
|
|
598
|
+
|
|
599
|
+
public ProxyTransform(Transform target, Transform parent, int charIndex)
|
|
600
|
+
{
|
|
601
|
+
Tweens = new List<Tween>();
|
|
602
|
+
this.target = target;
|
|
603
|
+
this.parent = parent;
|
|
604
|
+
AssignCharIndex(charIndex);
|
|
605
|
+
Target.localPosition = Vector3.zero;
|
|
606
|
+
}
|
|
607
|
+
|
|
608
|
+
public ProxyTransform(Transform target, Transform parent, TMP_CharacterInfo charInfo)
|
|
609
|
+
{
|
|
610
|
+
Tweens = new List<Tween>();
|
|
611
|
+
this.target = target;
|
|
612
|
+
this.parent = parent;
|
|
613
|
+
AssignCharInfo(charInfo);
|
|
614
|
+
Target.localPosition = Vector3.zero;
|
|
615
|
+
}
|
|
616
|
+
|
|
617
|
+
public T AddTween<T>(T tween) where T : Tween
|
|
618
|
+
{
|
|
619
|
+
Tweens.Add(tween);
|
|
620
|
+
return tween;
|
|
621
|
+
}
|
|
622
|
+
|
|
623
|
+
public void CompleteAll(bool withCallbacks = false)
|
|
624
|
+
{
|
|
625
|
+
for (var i = 0; i < Tweens.Count; i++)
|
|
626
|
+
Tweens[i].Complete(withCallbacks);
|
|
627
|
+
Tweens.Clear();
|
|
628
|
+
}
|
|
629
|
+
|
|
630
|
+
public void KillAll(bool complete = false)
|
|
631
|
+
{
|
|
632
|
+
for (var i = 0; i < Tweens.Count; i++)
|
|
633
|
+
Tweens[i].Kill(complete);
|
|
634
|
+
Tweens.Clear();
|
|
635
|
+
}
|
|
636
|
+
|
|
637
|
+
public void DisposeFinishedTweens()
|
|
638
|
+
{
|
|
639
|
+
if (Tweens.Count == 0)
|
|
640
|
+
return;
|
|
641
|
+
|
|
642
|
+
for (int i = Tweens.Count - 1; i >= 0; i--)
|
|
643
|
+
{
|
|
644
|
+
Tween tween = Tweens[i];
|
|
645
|
+
if (!tween.active)
|
|
646
|
+
Tweens.RemoveAt(i);
|
|
647
|
+
}
|
|
648
|
+
}
|
|
649
|
+
|
|
650
|
+
public void AssignCharInfo(TMP_CharacterInfo charInfo)
|
|
651
|
+
{
|
|
652
|
+
charIndex = charInfo.index;
|
|
653
|
+
if (charInfo.isVisible)
|
|
654
|
+
{
|
|
655
|
+
localStartPosition = new Vector3(
|
|
656
|
+
(charInfo.topLeft.x + charInfo.bottomRight.x) * 0.5f,
|
|
657
|
+
(charInfo.topLeft.y + charInfo.bottomRight.y) * 0.5f,
|
|
658
|
+
(charInfo.topLeft.z + charInfo.bottomRight.z) * 0.5f
|
|
659
|
+
);
|
|
660
|
+
}
|
|
661
|
+
else
|
|
662
|
+
{
|
|
663
|
+
localStartPosition = Vector3.zero;
|
|
664
|
+
}
|
|
665
|
+
}
|
|
666
|
+
|
|
667
|
+
public void AssignCharIndex(int charIndex)
|
|
668
|
+
{
|
|
669
|
+
this.charIndex = charIndex;
|
|
670
|
+
localStartPosition = Vector3.zero;
|
|
671
|
+
}
|
|
672
|
+
|
|
673
|
+
public Tweener DOMove(Vector3 endValue, float duration, bool snapping = false)
|
|
674
|
+
{
|
|
675
|
+
return snapping
|
|
676
|
+
? DOTween.To(GetPosition, SetPositionAndSnap, endValue, duration).SetTarget(target)
|
|
677
|
+
: DOTween.To(GetPosition, SetPosition, endValue, duration).SetTarget(target);
|
|
678
|
+
}
|
|
679
|
+
|
|
680
|
+
public Tweener DOMoveX(float endValue, float duration, bool snapping = false)
|
|
681
|
+
{
|
|
682
|
+
return snapping
|
|
683
|
+
? DOTween.ToAxis(GetPosition, SetPositionAndSnap, endValue, duration, AxisConstraint.X).SetTarget(target)
|
|
684
|
+
: DOTween.ToAxis(GetPosition, SetPosition, endValue, duration, AxisConstraint.X).SetTarget(target);
|
|
685
|
+
}
|
|
686
|
+
|
|
687
|
+
public Tweener DOMoveY(float endValue, float duration, bool snapping = false)
|
|
688
|
+
{
|
|
689
|
+
return snapping
|
|
690
|
+
? DOTween.ToAxis(GetPosition, SetPositionAndSnap, endValue, duration, AxisConstraint.Y).SetTarget(target)
|
|
691
|
+
: DOTween.ToAxis(GetPosition, SetPosition, endValue, duration, AxisConstraint.Y).SetTarget(target);
|
|
692
|
+
}
|
|
693
|
+
|
|
694
|
+
public Tweener DOMoveZ(float endValue, float duration, bool snapping = false)
|
|
695
|
+
{
|
|
696
|
+
return snapping
|
|
697
|
+
? DOTween.ToAxis(GetPosition, SetPositionAndSnap, endValue, duration, AxisConstraint.Z).SetTarget(target)
|
|
698
|
+
: DOTween.ToAxis(GetPosition, SetPosition, endValue, duration, AxisConstraint.Z).SetTarget(target);
|
|
699
|
+
}
|
|
700
|
+
|
|
701
|
+
public Tweener DOLocalMove(Vector3 endValue, float duration, bool snapping = false)
|
|
702
|
+
{
|
|
703
|
+
return snapping
|
|
704
|
+
? DOTween.To(GetLocalPosition, SetLocalPositionAndSnap, endValue, duration).SetTarget(target)
|
|
705
|
+
: DOTween.To(GetLocalPosition, SetLocalPosition, endValue, duration).SetTarget(target);
|
|
706
|
+
}
|
|
707
|
+
|
|
708
|
+
public Tweener DOLocalMoveX(float endValue, float duration, bool snapping = false)
|
|
709
|
+
{
|
|
710
|
+
return snapping
|
|
711
|
+
? DOTween.ToAxis(GetLocalPosition, SetLocalPositionAndSnap, endValue, duration, AxisConstraint.X).SetTarget(target)
|
|
712
|
+
: DOTween.ToAxis(GetLocalPosition, SetLocalPosition, endValue, duration, AxisConstraint.X).SetTarget(target);
|
|
713
|
+
}
|
|
714
|
+
|
|
715
|
+
public Tweener DOLocalMoveY(float endValue, float duration, bool snapping = false)
|
|
716
|
+
{
|
|
717
|
+
return snapping
|
|
718
|
+
? DOTween.ToAxis(GetLocalPosition, SetLocalPositionAndSnap, endValue, duration, AxisConstraint.Y).SetTarget(target)
|
|
719
|
+
: DOTween.ToAxis(GetLocalPosition, SetLocalPosition, endValue, duration, AxisConstraint.Y).SetTarget(target);
|
|
720
|
+
}
|
|
721
|
+
|
|
722
|
+
public Tweener DOLocalMoveZ(float endValue, float duration, bool snapping = false)
|
|
723
|
+
{
|
|
724
|
+
return snapping
|
|
725
|
+
? DOTween.ToAxis(GetLocalPosition, SetLocalPositionAndSnap, endValue, duration, AxisConstraint.Z).SetTarget(target)
|
|
726
|
+
: DOTween.ToAxis(GetLocalPosition, SetLocalPosition, endValue, duration, AxisConstraint.Z).SetTarget(target);
|
|
727
|
+
}
|
|
728
|
+
|
|
729
|
+
// These getters and setters are for use with DOTween.To
|
|
730
|
+
public Vector3 GetLocalPosition() { return LocalPosition; }
|
|
731
|
+
public void SetLocalPosition(Vector3 value) { LocalPosition = value; }
|
|
732
|
+
|
|
733
|
+
public void SetLocalPositionAndSnap(Vector3 value)
|
|
734
|
+
{
|
|
735
|
+
LocalPosition = new Vector3(Mathf.Round(value.x), Mathf.Round(value.y), Mathf.Round(value.z));
|
|
736
|
+
}
|
|
737
|
+
|
|
738
|
+
public Vector3 GetPosition() { return Position; }
|
|
739
|
+
public void SetPosition(Vector3 value) { Position = value; }
|
|
740
|
+
|
|
741
|
+
public void SetPositionAndSnap(Vector3 value)
|
|
742
|
+
{
|
|
743
|
+
Position = new Vector3(Mathf.Round(value.x), Mathf.Round(value.y), Mathf.Round(value.z));
|
|
744
|
+
}
|
|
745
|
+
}
|
|
746
|
+
}
|
|
747
|
+
}
|
|
748
748
|
#endif
|