少年修仙传客户端基础资源
lwb
2020-11-20 523a8c5b8de799aeaeaa7287f0b4f9e2edf339ee
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
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
// 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
 
 
#if false // MODULE_MARKER
using System;
using System.Globalization;
using System.Collections.Generic;
using DG.Tweening.Core;
using DG.Tweening.Plugins.Options;
using UnityEngine;
using TMPro;
using Object = UnityEngine.Object;
 
namespace DG.Tweening
{
    public enum TMPSkewSpanMode
    {
        /// <summary>Applies the skew as-is (like normal skew works): the longer the text-span the higher the last character will be</summary>
        Default,
        /// <summary>Applies the skew scaled by the size of the text-span: the max skew/displacement will be the given skew factor</summary>
        AsMaxSkewFactor
    }
 
    /// <summary>
    /// Methods that extend TMP_Text objects and allow to directly create and control tweens from their instances.
    /// </summary>
    public static class ShortcutExtensionsTMPText
    {
        #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 TweenerCore<Color, Color, ColorOptions> DOColor(this TMP_Text target, Color endValue, float duration)
        {
            TweenerCore<Color, Color, ColorOptions> t = DOTween.To(() => target.color, x => target.color = x, endValue, duration);
            t.SetTarget(target);
            return t;
        }
 
        /// <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 TweenerCore<Color, Color, ColorOptions> DOFaceColor(this TMP_Text target, Color32 endValue, float duration)
        {
            TweenerCore<Color, Color, ColorOptions> t = DOTween.To(() => target.faceColor, x => target.faceColor = x, endValue, duration);
            t.SetTarget(target);
            return t;
        }
 
        /// <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 TweenerCore<Color, Color, ColorOptions> DOOutlineColor(this TMP_Text target, Color32 endValue, float duration)
        {
            TweenerCore<Color, Color, ColorOptions> t = DOTween.To(() => target.outlineColor, x => target.outlineColor = x, endValue, duration);
            t.SetTarget(target);
            return t;
        }
 
        /// <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 TweenerCore<Color, Color, ColorOptions> DOGlowColor(this TMP_Text target, Color endValue, float duration, bool useSharedMaterial = false)
        {
            TweenerCore<Color, Color, ColorOptions> t = useSharedMaterial
                ? target.fontSharedMaterial.DOColor(endValue, "_GlowColor", duration)
                : target.fontMaterial.DOColor(endValue, "_GlowColor", duration);
            t.SetTarget(target);
            return t;
        }
 
        /// <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 TweenerCore<Color, Color, ColorOptions> DOFade(this TMP_Text target, float endValue, float duration)
        {
            TweenerCore<Color, Color, ColorOptions> t = DOTween.ToAlpha(() => target.color, x => target.color = x, endValue, duration);
            t.SetTarget(target);
            return t;
        }
 
        /// <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 TweenerCore<Color, Color, ColorOptions> DOFaceFade(this TMP_Text target, float endValue, float duration)
        {
            TweenerCore<Color, Color, ColorOptions> t = DOTween.ToAlpha(() => target.faceColor, x => target.faceColor = x, endValue, duration);
            t.SetTarget(target);
            return t;
        }
 
        #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 TweenerCore<Vector3, Vector3, VectorOptions> DOScale(this TMP_Text target, float endValue, float duration)
        {
            Transform trans = target.transform;
            Vector3 endValueV3 = new Vector3(endValue, endValue, endValue);
            TweenerCore<Vector3, Vector3, VectorOptions> t = DOTween.To(() => trans.localScale, x => trans.localScale = x, endValueV3, duration);
            t.SetTarget(target);
            return t;
        }
 
        /// <summary>
        /// Tweens a TextMeshPro's text from one integer to another, with options for thousands separators
        /// </summary>
        /// <param name="fromValue">The value to start from</param>
        /// <param name="endValue">The end value to reach</param>
        /// <param name="duration">The duration of the tween</param>
        /// <param name="addThousandsSeparator">If TRUE (default) also adds thousands separators</param>
        /// <param name="culture">The <see cref="CultureInfo"/> to use (InvariantCulture if NULL)</param>
        public static TweenerCore<int, int, NoOptions> DOCounter(
            this TMP_Text target, int fromValue, int endValue, float duration, bool addThousandsSeparator = true, CultureInfo culture = null
        ){
            int v = fromValue;
            CultureInfo cInfo = !addThousandsSeparator ? null : culture ?? CultureInfo.InvariantCulture;
            TweenerCore<int, int, NoOptions> t = DOTween.To(() => v, x => {
                v = x;
                target.text = addThousandsSeparator
                    ? v.ToString("N0", cInfo)
                    : v.ToString();
            }, endValue, duration);
            t.SetTarget(target);
            return t;
        }
 
        /// <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 TweenerCore<float, float, FloatOptions> DOFontSize(this TMP_Text target, float endValue, float duration)
        {
            TweenerCore<float, float, FloatOptions> t = DOTween.To(() => target.fontSize, x => target.fontSize = x, endValue, duration);
            t.SetTarget(target);
            return t;
        }
 
        /// <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 TweenerCore<int, int, NoOptions> DOMaxVisibleCharacters(this TMP_Text target, int endValue, float duration)
        {
            TweenerCore<int, int, NoOptions> t = DOTween.To(() => target.maxVisibleCharacters, x => target.maxVisibleCharacters = x, endValue, duration);
            t.SetTarget(target);
            return t;
        }
 
        /// <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 TweenerCore<string, string, StringOptions> DOText(this TMP_Text target, string endValue, float duration, bool richTextEnabled = true, ScrambleMode scrambleMode = ScrambleMode.None, string scrambleChars = null)
        {
            TweenerCore<string, string, StringOptions> t = DOTween.To(() => target.text, x => target.text = x, endValue, duration);
            t.SetOptions(richTextEnabled, scrambleMode, scrambleChars)
                .SetTarget(target);
            return t;
        }
 
        #endregion
    }
 
    #region DOTweenTMPAnimator
 
    // █████████████████████████████████████████████████████████████████████████████████████████████████████████████████████
    // ███ CLASS ███████████████████████████████████████████████████████████████████████████████████████████████████████████
    // █████████████████████████████████████████████████████████████████████████████████████████████████████████████████████
 
    /// <summary>
    /// Wrapper for <see cref="TMP_Text"/> objects that enables per-character tweening
    /// (you don't need this if instead you want to animate the whole text object).
    /// It also contains various handy methods to simply deform text without animating it ;)
    /// <para><code>EXAMPLE:<para/>
    /// DOTweenTMPAnimator animator = new DOTweenTMPAnimator(myTextMeshProTextField);<para/>
    /// Tween tween = animator.DOCharScale(characterIndex, scaleValue, duration);
    /// </code></para>
    /// </summary>
    public class DOTweenTMPAnimator : IDisposable
    {
        /// <summary><see cref="TMP_Text"/> that this animator is linked to</summary>
        public TMP_Text target { get; private set; }
        public TMP_TextInfo textInfo { get; private set; }
        readonly List<CharTransform> _charTransforms = new List<CharTransform>();
        TMP_MeshInfo[] _cachedMeshInfos;
        bool _ignoreTextChangedEvent;
 
        /// <summary>
        /// Creates a new instance of the <see cref="DOTweenTMPAnimator"/>, which is necessary to animate <see cref="TMP_Text"/> by single characters.
        /// If you want to animate the whole text object you don't need this, and you can use direct <see cref="TMP_Text"/> DO shortcuts instead.<para/>
        /// IMPORTANT: the <see cref="TMP_Text"/> target must have been enabled/activated at least once before you can use it with this
        /// </summary>
        /// <param name="target">The <see cref="TMP_Text"/> that will be linked to this animator</param>
        public DOTweenTMPAnimator(TMP_Text target)
        {
            if (!target.gameObject.activeInHierarchy) {
                Debugger.LogError("You can't create a DOTweenTMPAnimator if its target is disabled");
                return;
            }
            this.target = target;
            Refresh();
            // Listeners
            TMPro_EventManager.TEXT_CHANGED_EVENT.Add(OnTextChanged);
        }
 
        /// <summary>
        /// Clears and disposes of this object
        /// </summary>
        public void Dispose()
        {
            target = null;
            _charTransforms.Clear();
            textInfo = null;
            _cachedMeshInfos = null;
            TMPro_EventManager.TEXT_CHANGED_EVENT.Remove(OnTextChanged);
        }
 
        /// <summary>
        /// Refreshes the animator text data and resets all transformation data. Call this after you change the target <see cref="TMP_Text"/>
        /// </summary>
        public void Refresh()
        {
            _ignoreTextChangedEvent = true;
            target.ForceMeshUpdate(true);
            textInfo = target.textInfo;
            _cachedMeshInfos = textInfo.CopyMeshInfoVertexData();
            int totChars = textInfo.characterCount;
            int totCurrent = _charTransforms.Count;
            if (totCurrent > totChars) {
                _charTransforms.RemoveRange(totChars, totCurrent - totChars);
                totCurrent = totChars;
            }
            for (int i = 0; i < totCurrent; ++i) {
                CharTransform c = _charTransforms[i];
                c.ResetTransformationData();
                c.Refresh(textInfo, _cachedMeshInfos);
                _charTransforms[i] = c;
            }
            for (int i = totCurrent; i < totChars; ++i) _charTransforms.Add(new CharTransform(i, textInfo, _cachedMeshInfos));
            _ignoreTextChangedEvent = false;
        }
 
        /// <summary>
        /// Resets all deformations
        /// </summary>
        public void Reset()
        {
            int totCurrent = _charTransforms.Count;
            for (int i = 0; i < totCurrent; ++i) _charTransforms[i].ResetAll(target, textInfo.meshInfo, _cachedMeshInfos);
        }
 
        void OnTextChanged(Object obj)
        {
            if (_ignoreTextChangedEvent || target == null || obj != target) return;
            Refresh();
        }
 
        bool ValidateChar(int charIndex, bool isTween = true)
        {
            if (textInfo.characterCount <= charIndex) {
                Debugger.LogError(string.Format("CharIndex {0} doesn't exist", charIndex));
                return false;
            }
            if (!textInfo.characterInfo[charIndex].isVisible) {
                if (Debugger.logPriority > 1) {
                    if (isTween) {
                        Debugger.Log(string.Format(
                            "CharIndex {0} isn't visible, ignoring it and returning an empty tween (TextMesh Pro will behave weirdly if invisible chars are included in the animation)",
                            charIndex
                        ));
                    } else {
                        Debugger.Log(string.Format("CharIndex {0} isn't visible, ignoring it", charIndex));
                    }
                }
                return false;
            }
            return true;
        }
 
        bool ValidateSpan(int fromCharIndex, int toCharIndex, out int firstVisibleCharIndex, out int lastVisibleCharIndex)
        {
            firstVisibleCharIndex = -1; // First visible/existing charIndex from given index
            lastVisibleCharIndex = -1; // Last visible/existing charIndex backwards from given index
            int charCount = textInfo.characterCount;
            if (fromCharIndex >= charCount) return false;
            if (toCharIndex >= charCount) toCharIndex = charCount - 1;
            for (int i = fromCharIndex; i < toCharIndex + 1; ++i) {
                if (!_charTransforms[i].isVisible) continue;
                firstVisibleCharIndex = i;
                break;
            }
            if (firstVisibleCharIndex == -1) return false;
            for (int i = toCharIndex; i > firstVisibleCharIndex - 1; --i) {
                if (!_charTransforms[i].isVisible) continue;
                lastVisibleCharIndex = i;
                break;
            }
            if (lastVisibleCharIndex == -1) return false;
            return true;
        }
 
        #region Word Setters
 
        /// <summary>
        /// Skews a span of characters uniformly (like normal skew works in graphic applications)
        /// </summary>
        /// <param name="fromCharIndex">First char index of the span to skew</param>
        /// <param name="toCharIndex">Last char index of the span to skew</param>
        /// <param name="skewFactor">Skew factor</param>
        /// <param name="skewTop">If TRUE skews the top side of the span, otherwise the bottom one</param>
        public void SkewSpanX(int fromCharIndex, int toCharIndex, float skewFactor, bool skewTop = true)
        {
            int firstVisibleCharIndex, lastVisibleCharIndex;
            if (!ValidateSpan(fromCharIndex, toCharIndex, out firstVisibleCharIndex, out lastVisibleCharIndex)) return;
            for (int i = firstVisibleCharIndex; i < lastVisibleCharIndex + 1; ++i) {
                if (!_charTransforms[i].isVisible) continue;
                CharVertices v = _charTransforms[i].GetVertices();
                float skew = SkewCharX(i, skewFactor, skewTop);
            }
        }
 
        /// <summary>
        /// Skews a span of characters uniformly (like normal skew works in graphic applications)
        /// </summary>
        /// <param name="fromCharIndex">First char index of the span to skew</param>
        /// <param name="toCharIndex">Last char index of the span to skew</param>
        /// <param name="skewFactor">Skew factor</param>
        /// <param name="mode">Skew mode</param>
        /// <param name="skewRight">If TRUE skews the right side of the span, otherwise the left one</param>
        public void SkewSpanY(
            int fromCharIndex, int toCharIndex, float skewFactor,
            TMPSkewSpanMode mode = TMPSkewSpanMode.Default, bool skewRight = true
        ){
            int firstVisibleCharIndex, lastVisibleCharIndex;
            if (!ValidateSpan(fromCharIndex, toCharIndex, out firstVisibleCharIndex, out lastVisibleCharIndex)) return;
            if (mode == TMPSkewSpanMode.AsMaxSkewFactor) {
                CharVertices firstVisibleCharVertices = _charTransforms[firstVisibleCharIndex].GetVertices();
                CharVertices lastVisibleCharVertices = _charTransforms[lastVisibleCharIndex].GetVertices();
                float spanW = Mathf.Abs(lastVisibleCharVertices.bottomRight.x - firstVisibleCharVertices.bottomLeft.x);
                float spanH = Mathf.Abs(lastVisibleCharVertices.topRight.y - lastVisibleCharVertices.bottomRight.y);
                float ratio = spanH / spanW;
                skewFactor *= ratio;
            }
            float offsetY = 0;
            CharVertices prevCharVertices = new CharVertices();
            float prevCharSkew = 0;
            if (skewRight) {
                for (int i = firstVisibleCharIndex; i < lastVisibleCharIndex + 1; ++i) {
                    if (!_charTransforms[i].isVisible) continue;
                    CharVertices v = _charTransforms[i].GetVertices();
                    float skew = SkewCharY(i, skewFactor, skewRight);
                    if (i > firstVisibleCharIndex) {
                        float prevCharW = Mathf.Abs(prevCharVertices.bottomLeft.x - prevCharVertices.bottomRight.x);
                        float charsDist = Mathf.Abs(v.bottomLeft.x - prevCharVertices.bottomRight.x);
                        offsetY += prevCharSkew + (prevCharSkew * charsDist) / prevCharW;
                        SetCharOffset(i, new Vector3(0, _charTransforms[i].offset.y + offsetY, 0));
                    }
                    prevCharVertices = v;
                    prevCharSkew = skew;
                }
            } else {
                for (int i = lastVisibleCharIndex; i > firstVisibleCharIndex - 1; --i) {
                    if (!_charTransforms[i].isVisible) continue;
                    CharVertices v = _charTransforms[i].GetVertices();
                    float skew = SkewCharY(i, skewFactor, skewRight);
                    if (i < lastVisibleCharIndex) {
                        float prevCharW = Mathf.Abs(prevCharVertices.bottomLeft.x - prevCharVertices.bottomRight.x);
                        float charsDist = Mathf.Abs(v.bottomRight.x - prevCharVertices.bottomLeft.x);
                        offsetY += prevCharSkew + (prevCharSkew * charsDist) / prevCharW;
                        SetCharOffset(i, new Vector3(0, _charTransforms[i].offset.y + offsetY, 0));
                    }
                    prevCharVertices = v;
                    prevCharSkew = skew;
                }
            }
        }
 
        #endregion
 
        #region Char Getters
 
        /// <summary>
        /// Returns the current color of the given character, if it exists and is visible.
        /// </summary>
        /// <param name="charIndex">Character index</param>
        public Color GetCharColor(int charIndex)
        {
            if (!ValidateChar(charIndex)) return Color.white;
            return _charTransforms[charIndex].GetColor(textInfo.meshInfo);
        }
 
        /// <summary>
        /// Returns the current offset of the given character, if it exists and is visible.
        /// </summary>
        /// <param name="charIndex">Character index</param>
        public Vector3 GetCharOffset(int charIndex)
        {
            if (!ValidateChar(charIndex)) return Vector3.zero;
            return _charTransforms[charIndex].offset;
        }
 
        /// <summary>
        /// Returns the current rotation of the given character, if it exists and is visible.
        /// </summary>
        /// <param name="charIndex">Character index</param>
        public Vector3 GetCharRotation(int charIndex)
        {
            if (!ValidateChar(charIndex)) return Vector3.zero;
            return _charTransforms[charIndex].rotation.eulerAngles;
        }
 
        /// <summary>
        /// Returns the current scale of the given character, if it exists and is visible.
        /// </summary>
        /// <param name="charIndex">Character index</param>
        public Vector3 GetCharScale(int charIndex)
        {
            if (!ValidateChar(charIndex)) return Vector3.zero;
            return _charTransforms[charIndex].scale;
        }
 
        #endregion
 
        #region Char Setters
 
        /// <summary>
        /// Immediately sets the color of the given character.
        /// Will do nothing if the <see cref="charIndex"/> is invalid or the character isn't visible
        /// </summary>
        /// <param name="charIndex">Character index</param>
        /// <param name="color">Color to set</param>
        public void SetCharColor(int charIndex, Color32 color)
        {
            if (!ValidateChar(charIndex)) return;
            CharTransform c = _charTransforms[charIndex];
            c.UpdateColor(target, color, textInfo.meshInfo);
            _charTransforms[charIndex] = c;
        }
 
        /// <summary>
        /// Immediately sets the offset of the given character.
        /// Will do nothing if the <see cref="charIndex"/> is invalid or the character isn't visible
        /// </summary>
        /// <param name="charIndex">Character index</param>
        /// <param name="offset">Offset to set</param>
        public void SetCharOffset(int charIndex, Vector3 offset)
        {
            if (!ValidateChar(charIndex)) return;
            CharTransform c = _charTransforms[charIndex];
            c.UpdateGeometry(target, offset, c.rotation, c.scale, _cachedMeshInfos);
            _charTransforms[charIndex] = c;
        }
 
        /// <summary>
        /// Immediately sets the rotation of the given character.
        /// Will do nothing if the <see cref="charIndex"/> is invalid or the character isn't visible
        /// </summary>
        /// <param name="charIndex">Character index</param>
        /// <param name="rotation">Rotation to set</param>
        public void SetCharRotation(int charIndex, Vector3 rotation)
        {
            if (!ValidateChar(charIndex)) return;
            CharTransform c = _charTransforms[charIndex];
            c.UpdateGeometry(target, c.offset, Quaternion.Euler(rotation), c.scale, _cachedMeshInfos);
            _charTransforms[charIndex] = c;
        }
 
        /// <summary>
        /// Immediately sets the scale of the given character.
        /// Will do nothing if the <see cref="charIndex"/> is invalid or the character isn't visible
        /// </summary>
        /// <param name="charIndex">Character index</param>
        /// <param name="scale">Scale to set</param>
        public void SetCharScale(int charIndex, Vector3 scale)
        {
            if (!ValidateChar(charIndex)) return;
            CharTransform c = _charTransforms[charIndex];
            c.UpdateGeometry(target, c.offset, c.rotation, scale, _cachedMeshInfos);
            _charTransforms[charIndex] = c;
        }
 
        /// <summary>
        /// Immediately shifts the vertices of the given character by the given factor.
        /// Will do nothing if the <see cref="charIndex"/> is invalid or the character isn't visible
        /// </summary>
        /// <param name="charIndex">Character index</param>
        /// <param name="topLeftShift">Top left offset</param>
        /// <param name="topRightShift">Top right offset</param>
        /// <param name="bottomLeftShift">Bottom left offset</param>
        /// <param name="bottomRightShift">Bottom right offset</param>
        public void ShiftCharVertices(int charIndex, Vector3 topLeftShift, Vector3 topRightShift, Vector3 bottomLeftShift, Vector3 bottomRightShift)
        {
            if (!ValidateChar(charIndex)) return;
            CharTransform c = _charTransforms[charIndex];
            c.ShiftVertices(target, topLeftShift, topRightShift, bottomLeftShift, bottomRightShift);
            _charTransforms[charIndex] = c;
        }
 
        /// <summary>
        /// Skews the given character horizontally along the X axis and returns the skew amount applied (based on the character's size)
        /// </summary>
        /// <param name="charIndex">Character index</param>
        /// <param name="skewFactor">skew amount</param>
        /// <param name="skewTop">If TRUE skews the top side of the character, otherwise the bottom one</param>
        public float SkewCharX(int charIndex, float skewFactor, bool skewTop = true)
        {
            if (!ValidateChar(charIndex)) return 0;
            Vector3 skewV = new Vector3(skewFactor, 0, 0);
            CharTransform c = _charTransforms[charIndex];
            if (skewTop) c.ShiftVertices(target, skewV, skewV, Vector3.zero, Vector3.zero);
            else c.ShiftVertices(target, Vector3.zero, Vector3.zero, skewV, skewV);
            _charTransforms[charIndex] = c;
            return skewFactor;
        }
 
        /// <summary>
        /// Skews the given character vertically along the Y axis and returns the skew amount applied (based on the character's size)
        /// </summary>
        /// <param name="charIndex">Character index</param>
        /// <param name="skewFactor">skew amount</param>
        /// <param name="skewRight">If TRUE skews the right side of the character, otherwise the left one</param>
        /// <param name="fixedSkew">If TRUE applies exactly the given <see cref="skewFactor"/>,
        /// otherwise modifies it based on the aspectRation of the character</param>
        public float SkewCharY(int charIndex, float skewFactor, bool skewRight = true, bool fixedSkew = false)
        {
            if (!ValidateChar(charIndex)) return 0;
            float skew = fixedSkew ? skewFactor : skewFactor * textInfo.characterInfo[charIndex].aspectRatio;
            Vector3 skewV = new Vector3(0, skew, 0);
            CharTransform c = _charTransforms[charIndex];
            if (skewRight) c.ShiftVertices(target, Vector3.zero, skewV, Vector3.zero, skewV);
            else c.ShiftVertices(target, skewV, Vector3.zero, skewV, Vector3.zero);
            _charTransforms[charIndex] = c;
            return skew;
        }
 
        /// <summary>
        /// Resets the eventual vertices shift applied to the given character via <see cref="ShiftCharVertices"/>.
        /// Will do nothing if the <see cref="charIndex"/> is invalid or the character isn't visible
        /// </summary>
        /// <param name="charIndex">Character index</param>
        public void ResetVerticesShift(int charIndex)
        {
            if (!ValidateChar(charIndex)) return;
            CharTransform c = _charTransforms[charIndex];
            c.ResetVerticesShift(target);
            _charTransforms[charIndex] = c;
        }
 
        #endregion
 
        #region Char Tweens
 
        /// <summary>Tweens a character's alpha to the given value and returns the <see cref="Tween"/>.
        /// Will return NULL if the <see cref="charIndex"/> is invalid or the character isn't visible.</summary>
        /// <param name="charIndex">The index of the character to tween (will throw an error if it doesn't exist)</param>
        /// <param name="endValue">The end value to reach</param><param name="duration">The duration of the tween</param>
        public TweenerCore<Color, Color, ColorOptions> DOFadeChar(int charIndex, float endValue, float duration)
        {
            if (!ValidateChar(charIndex)) return null;
            TweenerCore<Color, Color, ColorOptions> t = DOTween.ToAlpha(() => _charTransforms[charIndex].GetColor(textInfo.meshInfo), x => {
                _charTransforms[charIndex].UpdateAlpha(target, x, textInfo.meshInfo);
            }, endValue, duration);
            return t;
        }
 
        /// <summary>Tweens a character's color to the given value and returns the <see cref="Tween"/>.
        /// Will return NULL if the <see cref="charIndex"/> is invalid or the character isn't visible.</summary>
        /// <param name="charIndex">The index of the character to tween (will throw an error if it doesn't exist)</param>
        /// <param name="endValue">The end value to reach</param><param name="duration">The duration of the tween</param>
        public TweenerCore<Color, Color, ColorOptions> DOColorChar(int charIndex, Color endValue, float duration)
        {
            if (!ValidateChar(charIndex)) return null;
            TweenerCore<Color, Color, ColorOptions> t = DOTween.To(() => _charTransforms[charIndex].GetColor(textInfo.meshInfo), x => {
                _charTransforms[charIndex].UpdateColor(target, x, textInfo.meshInfo);
            }, endValue, duration);
            return t;
        }
 
        /// <summary>Tweens a character's offset to the given value and returns the <see cref="Tween"/>.
        /// Will return NULL if the <see cref="charIndex"/> is invalid or the character isn't visible.</summary>
        /// <param name="charIndex">The index of the character to tween (will throw an error if it doesn't exist)</param>
        /// <param name="endValue">The end value to reach</param><param name="duration">The duration of the tween</param>
        public TweenerCore<Vector3, Vector3, VectorOptions> DOOffsetChar(int charIndex, Vector3 endValue, float duration)
        {
            if (!ValidateChar(charIndex)) return null;
            TweenerCore<Vector3, Vector3, VectorOptions> t = DOTween.To(() => _charTransforms[charIndex].offset, x => {
                CharTransform charT = _charTransforms[charIndex];
                charT.UpdateGeometry(target, x, charT.rotation, charT.scale, _cachedMeshInfos);
                _charTransforms[charIndex] = charT;
            }, endValue, duration);
            return t;
        }
 
        /// <summary>Tweens a character's rotation to the given value and returns the <see cref="Tween"/>.
        /// Will return NULL if the <see cref="charIndex"/> is invalid or the character isn't visible.</summary>
        /// <param name="charIndex">The index of the character to tween (will throw an error if it doesn't exist)</param>
        /// <param name="endValue">The end value to reach</param><param name="duration">The duration of the tween</param>
        /// <param name="mode">Rotation mode</param>
        public TweenerCore<Quaternion, Vector3, QuaternionOptions> DORotateChar(int charIndex, Vector3 endValue, float duration, RotateMode mode = RotateMode.Fast)
        {
            if (!ValidateChar(charIndex)) return null;
            TweenerCore<Quaternion, Vector3, QuaternionOptions> t = DOTween.To(() => _charTransforms[charIndex].rotation, x => {
                CharTransform charT = _charTransforms[charIndex];
                charT.UpdateGeometry(target, charT.offset, x, charT.scale, _cachedMeshInfos);
                _charTransforms[charIndex] = charT;
            }, endValue, duration);
            t.plugOptions.rotateMode = mode;
            return t;
        }
 
        /// <summary>Tweens a character's scale to the given value and returns the <see cref="Tween"/>.
        /// Will return NULL if the <see cref="charIndex"/> is invalid or the character isn't visible.</summary>
        /// <param name="charIndex">The index of the character to tween (will throw an error if it doesn't exist)</param>
        /// <param name="endValue">The end value to reach</param><param name="duration">The duration of the tween</param>
        public TweenerCore<Vector3, Vector3, VectorOptions> DOScaleChar(int charIndex, float endValue, float duration)
        {
            return DOScaleChar(charIndex, new Vector3(endValue, endValue, endValue), duration);
        }
        /// <summary>Tweens a character's color to the given value and returns the <see cref="Tween"/>.
        /// Will return NULL if the <see cref="charIndex"/> is invalid or the character isn't visible.</summary>
        /// <param name="charIndex">The index of the character to tween (will throw an error if it doesn't exist)</param>
        /// <param name="endValue">The end value to reach</param><param name="duration">The duration of the tween</param>
        public TweenerCore<Vector3, Vector3, VectorOptions> DOScaleChar(int charIndex, Vector3 endValue, float duration)
        {
            if (!ValidateChar(charIndex)) return null;
            TweenerCore<Vector3, Vector3, VectorOptions> t = DOTween.To(() => _charTransforms[charIndex].scale, x => {
                CharTransform charT = _charTransforms[charIndex];
                charT.UpdateGeometry(target, charT.offset, charT.rotation, x, _cachedMeshInfos);
                _charTransforms[charIndex] = charT;
            }, endValue, duration);
            return t;
        }
 
        /// <summary>Punches a character's offset towards the given direction and then back to the starting one
        /// as if it was connected to the starting position via an elastic.</summary>
        /// <param name="charIndex">The index of the character to tween (will throw an error if it doesn't exist)</param>
        /// <param name="punch">The punch strength</param>
        /// <param name="duration">The duration of the tween</param>
        /// <param name="vibrato">Indicates how much will the punch vibrate per second</param>
        /// <param name="elasticity">Represents how much (0 to 1) the vector will go beyond the starting size when bouncing backwards.
        /// 1 creates a full oscillation between the punch offset and the opposite offset,
        /// while 0 oscillates only between the punch offset and the start offset</param>
        public Tweener DOPunchCharOffset(int charIndex, Vector3 punch, float duration, int vibrato = 10, float elasticity = 1)
        {
            if (!ValidateChar(charIndex)) return null;
            if (duration <= 0) {
                if (Debugger.logPriority > 0) Debug.LogWarning("Duration can't be 0, returning NULL without creating a tween");
                return null;
            }
            return DOTween.Punch(() => _charTransforms[charIndex].offset, x => {
                CharTransform charT = _charTransforms[charIndex];
                charT.UpdateGeometry(target, x, charT.rotation, charT.scale, _cachedMeshInfos);
                _charTransforms[charIndex] = charT;
            }, punch, duration, vibrato, elasticity);
        }
 
        /// <summary>Punches a character's rotation towards the given direction and then back to the starting one
        /// as if it was connected to the starting position via an elastic.</summary>
        /// <param name="charIndex">The index of the character to tween (will throw an error if it doesn't exist)</param>
        /// <param name="punch">The punch strength</param>
        /// <param name="duration">The duration of the tween</param>
        /// <param name="vibrato">Indicates how much will the punch vibrate per second</param>
        /// <param name="elasticity">Represents how much (0 to 1) the vector will go beyond the starting size when bouncing backwards.
        /// 1 creates a full oscillation between the punch rotation and the opposite rotation,
        /// while 0 oscillates only between the punch rotation and the start rotation</param>
        public Tweener DOPunchCharRotation(int charIndex, Vector3 punch, float duration, int vibrato = 10, float elasticity = 1)
        {
            if (!ValidateChar(charIndex)) return null;
            if (duration <= 0) {
                if (Debugger.logPriority > 0) Debug.LogWarning("Duration can't be 0, returning NULL without creating a tween");
                return null;
            }
            return DOTween.Punch(() => _charTransforms[charIndex].rotation.eulerAngles, x => {
                CharTransform charT = _charTransforms[charIndex];
                charT.UpdateGeometry(target, charT.offset, Quaternion.Euler(x), charT.scale, _cachedMeshInfos);
                _charTransforms[charIndex] = charT;
            }, punch, duration, vibrato, elasticity);
        }
 
        /// <summary>Punches a character's scale towards the given direction and then back to the starting one
        /// as if it was connected to the starting position via an elastic.</summary>
        /// <param name="charIndex">The index of the character to tween (will throw an error if it doesn't exist)</param>
        /// <param name="punch">The punch strength (added to the character's current scale)</param>
        /// <param name="duration">The duration of the tween</param>
        /// <param name="vibrato">Indicates how much will the punch vibrate per second</param>
        /// <param name="elasticity">Represents how much (0 to 1) the vector will go beyond the starting size when bouncing backwards.
        /// 1 creates a full oscillation between the punch scale and the opposite scale,
        /// while 0 oscillates only between the punch scale and the start scale</param>
        public Tweener DOPunchCharScale(int charIndex, float punch, float duration, int vibrato = 10, float elasticity = 1)
        {
            return DOPunchCharScale(charIndex, new Vector3(punch, punch, punch), duration, vibrato, elasticity);
        }
        /// <summary>Punches a character's scale towards the given direction and then back to the starting one
        /// as if it was connected to the starting position via an elastic.</summary>
        /// <param name="charIndex">The index of the character to tween (will throw an error if it doesn't exist)</param>
        /// <param name="punch">The punch strength (added to the character's current scale)</param>
        /// <param name="duration">The duration of the tween</param>
        /// <param name="vibrato">Indicates how much will the punch vibrate per second</param>
        /// <param name="elasticity">Represents how much (0 to 1) the vector will go beyond the starting size when bouncing backwards.
        /// 1 creates a full oscillation between the punch scale and the opposite scale,
        /// while 0 oscillates only between the punch scale and the start scale</param>
        public Tweener DOPunchCharScale(int charIndex, Vector3 punch, float duration, int vibrato = 10, float elasticity = 1)
        {
            if (!ValidateChar(charIndex)) return null;
            if (duration <= 0) {
                if (Debugger.logPriority > 0) Debug.LogWarning("Duration can't be 0, returning NULL without creating a tween");
                return null;
            }
            return DOTween.Punch(() => _charTransforms[charIndex].scale, x => {
                CharTransform charT = _charTransforms[charIndex];
                charT.UpdateGeometry(target, charT.offset, charT.rotation, x, _cachedMeshInfos);
                _charTransforms[charIndex] = charT;
            }, punch, duration, vibrato, elasticity);
        }
 
        /// <summary>Shakes a character's offset with the given values.</summary>
        /// <param name="charIndex">The index of the character to tween (will throw an error if it doesn't exist)</param>
        /// <param name="duration">The duration of the tween</param>
        /// <param name="strength">The shake strength</param>
        /// <param name="vibrato">Indicates how much will the shake vibrate</param>
        /// <param name="randomness">Indicates how much the shake will be random (0 to 180 - values higher than 90 kind of suck, so beware). 
        /// Setting it to 0 will shake along a single direction.</param>
        /// <param name="fadeOut">If TRUE the shake will automatically fadeOut smoothly within the tween's duration, otherwise it will not</param>
        public Tweener DOShakeCharOffset(int charIndex, float duration, float strength, int vibrato = 10, float randomness = 90, bool fadeOut = true)
        {
            return DOShakeCharOffset(charIndex, duration, new Vector3(strength, strength, strength), vibrato, randomness, fadeOut);
        }
        /// <summary>Shakes a character's offset with the given values.</summary>
        /// <param name="charIndex">The index of the character to tween (will throw an error if it doesn't exist)</param>
        /// <param name="duration">The duration of the tween</param>
        /// <param name="strength">The shake strength</param>
        /// <param name="vibrato">Indicates how much will the shake vibrate</param>
        /// <param name="randomness">Indicates how much the shake will be random (0 to 180 - values higher than 90 kind of suck, so beware). 
        /// Setting it to 0 will shake along a single direction.</param>
        /// <param name="fadeOut">If TRUE the shake will automatically fadeOut smoothly within the tween's duration, otherwise it will not</param>
        public Tweener DOShakeCharOffset(int charIndex, float duration, Vector3 strength, int vibrato = 10, float randomness = 90, bool fadeOut = true)
        {
            if (!ValidateChar(charIndex)) return null;
            if (duration <= 0) {
                if (Debugger.logPriority > 0) Debug.LogWarning("Duration can't be 0, returning NULL without creating a tween");
                return null;
            }
            return DOTween.Shake(() => _charTransforms[charIndex].offset, x => {
                CharTransform charT = _charTransforms[charIndex];
                charT.UpdateGeometry(target, x, charT.rotation, charT.scale, _cachedMeshInfos);
                _charTransforms[charIndex] = charT;
            }, duration, strength, vibrato, randomness, fadeOut);
        }
 
        /// <summary>Shakes a character's rotation with the given values.</summary>
        /// <param name="charIndex">The index of the character to tween (will throw an error if it doesn't exist)</param>
        /// <param name="duration">The duration of the tween</param>
        /// <param name="strength">The shake strength</param>
        /// <param name="vibrato">Indicates how much will the shake vibrate</param>
        /// <param name="randomness">Indicates how much the shake will be random (0 to 180 - values higher than 90 kind of suck, so beware). 
        /// Setting it to 0 will shake along a single direction.</param>
        /// <param name="fadeOut">If TRUE the shake will automatically fadeOut smoothly within the tween's duration, otherwise it will not</param>
        public Tweener DOShakeCharRotation(int charIndex, float duration, Vector3 strength, int vibrato = 10, float randomness = 90, bool fadeOut = true)
        {
            if (!ValidateChar(charIndex)) return null;
            if (duration <= 0) {
                if (Debugger.logPriority > 0) Debug.LogWarning("Duration can't be 0, returning NULL without creating a tween");
                return null;
            }
            return DOTween.Shake(() => _charTransforms[charIndex].rotation.eulerAngles, x => {
                CharTransform charT = _charTransforms[charIndex];
                charT.UpdateGeometry(target, charT.offset, Quaternion.Euler(x), charT.scale, _cachedMeshInfos);
                _charTransforms[charIndex] = charT;
            }, duration, strength, vibrato, randomness, fadeOut);
        }
 
        /// <summary>Shakes a character's scale with the given values.</summary>
        /// <param name="charIndex">The index of the character to tween (will throw an error if it doesn't exist)</param>
        /// <param name="duration">The duration of the tween</param>
        /// <param name="strength">The shake strength</param>
        /// <param name="vibrato">Indicates how much will the shake vibrate</param>
        /// <param name="randomness">Indicates how much the shake will be random (0 to 180 - values higher than 90 kind of suck, so beware). 
        /// Setting it to 0 will shake along a single direction.</param>
        /// <param name="fadeOut">If TRUE the shake will automatically fadeOut smoothly within the tween's duration, otherwise it will not</param>
        public Tweener DOShakeCharScale(int charIndex, float duration, float strength, int vibrato = 10, float randomness = 90, bool fadeOut = true)
        {
            return DOShakeCharScale(charIndex, duration, new Vector3(strength, strength, strength), vibrato, randomness, fadeOut);
        }
        /// <summary>Shakes a character's scale with the given values.</summary>
        /// <param name="charIndex">The index of the character to tween (will throw an error if it doesn't exist)</param>
        /// <param name="duration">The duration of the tween</param>
        /// <param name="strength">The shake strength</param>
        /// <param name="vibrato">Indicates how much will the shake vibrate</param>
        /// <param name="randomness">Indicates how much the shake will be random (0 to 180 - values higher than 90 kind of suck, so beware). 
        /// Setting it to 0 will shake along a single direction.</param>
        /// <param name="fadeOut">If TRUE the shake will automatically fadeOut smoothly within the tween's duration, otherwise it will not</param>
        public Tweener DOShakeCharScale(int charIndex, float duration, Vector3 strength, int vibrato = 10, float randomness = 90, bool fadeOut = true)
        {
            if (!ValidateChar(charIndex)) return null;
            if (duration <= 0) {
                if (Debugger.logPriority > 0) Debug.LogWarning("Duration can't be 0, returning NULL without creating a tween");
                return null;
            }
            return DOTween.Shake(() => _charTransforms[charIndex].scale, x => {
                CharTransform charT = _charTransforms[charIndex];
                charT.UpdateGeometry(target, charT.offset, charT.rotation, x, _cachedMeshInfos);
                _charTransforms[charIndex] = charT;
            }, duration, strength, vibrato, randomness, fadeOut);
        }
 
        #endregion
 
        // ███ INTERNAL CLASSES ████████████████████████████████████████████████████████████████████████████████████████████████
 
        struct CharVertices
        {
            public Vector3 bottomLeft, topLeft, topRight, bottomRight;
 
            public CharVertices(Vector3 bottomLeft, Vector3 topLeft, Vector3 topRight, Vector3 bottomRight)
            {
                this.bottomLeft = bottomLeft;
                this.topLeft = topLeft;
                this.topRight = topRight;
                this.bottomRight = bottomRight;
            }
        }
 
        // █████████████████████████████████████████████████████████████████████████████████████████████████████████████████████
 
        // Vertices of each character are:
        // 0 : bottom left, 1 : top left, 2 : top right, 3 : bottom right
        struct CharTransform
        {
            public int charIndex;
            public bool isVisible { get; private set; } // FALSE both if it's invisible or if it's a space
            public Vector3 offset;
            public Quaternion rotation;
            public Vector3 scale;
            Vector3 _topLeftShift, _topRightShift, _bottomLeftShift, _bottomRightShift;
            Vector3 _charMidBaselineOffset;
            int _matIndex, _firstVertexIndex;
            TMP_MeshInfo _meshInfo;
 
            public CharTransform(int charIndex, TMP_TextInfo textInfo, TMP_MeshInfo[] cachedMeshInfos) : this()
            {
                this.charIndex = charIndex;
                offset = Vector3.zero;
                rotation = Quaternion.identity;
                scale = Vector3.one;
                Refresh(textInfo, cachedMeshInfos);
            }
 
            public void Refresh(TMP_TextInfo textInfo, TMP_MeshInfo[] cachedMeshInfos)
            {
                TMP_CharacterInfo charInfo = textInfo.characterInfo[charIndex];
                bool isSpaceChar = charInfo.character == ' ';
                isVisible = charInfo.isVisible && !isSpaceChar;
                _matIndex = charInfo.materialReferenceIndex;
                _firstVertexIndex = charInfo.vertexIndex;
                _meshInfo = textInfo.meshInfo[_matIndex];
                Vector3[] cachedVertices = cachedMeshInfos[_matIndex].vertices;
                _charMidBaselineOffset = isSpaceChar
                    ? Vector3.zero
                    : (cachedVertices[_firstVertexIndex] + cachedVertices[_firstVertexIndex + 2]) * 0.5f;
            }
 
            public void ResetAll(TMP_Text target, TMP_MeshInfo[] meshInfos, TMP_MeshInfo[] cachedMeshInfos)
            {
                ResetGeometry(target, cachedMeshInfos);
                ResetColors(target, meshInfos);
            }
 
            public void ResetTransformationData()
            {
                offset = Vector3.zero;
                rotation = Quaternion.identity;
                scale = Vector3.one;
                _topLeftShift = _topRightShift = _bottomLeftShift = _bottomRightShift = Vector3.zero;
            }
 
            public void ResetGeometry(TMP_Text target, TMP_MeshInfo[] cachedMeshInfos)
            {
                ResetTransformationData();
                Vector3[] destinationVertices = _meshInfo.vertices;
                Vector3[] cachedVertices = cachedMeshInfos[_matIndex].vertices;
                destinationVertices[_firstVertexIndex + 0] = cachedVertices[_firstVertexIndex + 0];
                destinationVertices[_firstVertexIndex + 1] = cachedVertices[_firstVertexIndex + 1];
                destinationVertices[_firstVertexIndex + 2] = cachedVertices[_firstVertexIndex + 2];
                destinationVertices[_firstVertexIndex + 3] = cachedVertices[_firstVertexIndex + 3];
                _meshInfo.mesh.vertices = _meshInfo.vertices;
                target.UpdateGeometry(_meshInfo.mesh, _matIndex);
            }
 
            public void ResetColors(TMP_Text target, TMP_MeshInfo[] meshInfos)
            {
                Color color = target.color;
                Color32[] vertexCols = meshInfos[_matIndex].colors32;
                vertexCols[_firstVertexIndex] = color;
                vertexCols[_firstVertexIndex + 1] = color;
                vertexCols[_firstVertexIndex + 2] = color;
                vertexCols[_firstVertexIndex + 3] = color;
                target.UpdateVertexData(TMP_VertexDataUpdateFlags.Colors32);
            }
 
            public Color32 GetColor(TMP_MeshInfo[] meshInfos)
            {
                return meshInfos[_matIndex].colors32[_firstVertexIndex];
            }
 
            public CharVertices GetVertices()
            {
                return new CharVertices(
                    _meshInfo.vertices[_firstVertexIndex], _meshInfo.vertices[_firstVertexIndex + 1],
                    _meshInfo.vertices[_firstVertexIndex + 2], _meshInfo.vertices[_firstVertexIndex + 3]
                );
            }
 
            public void UpdateAlpha(TMP_Text target, Color alphaColor, TMP_MeshInfo[] meshInfos, bool apply = true)
            {
                byte alphaByte = (byte)(alphaColor.a * 255);
                Color32[] vertexCols = meshInfos[_matIndex].colors32;
                vertexCols[_firstVertexIndex].a = alphaByte;
                vertexCols[_firstVertexIndex + 1].a = alphaByte;
                vertexCols[_firstVertexIndex + 2].a = alphaByte;
                vertexCols[_firstVertexIndex + 3].a = alphaByte;
                if (apply) target.UpdateVertexData(TMP_VertexDataUpdateFlags.Colors32);
            }
 
            public void UpdateColor(TMP_Text target, Color32 color, TMP_MeshInfo[] meshInfos, bool apply = true)
            {
                Color32[] vertexCols = meshInfos[_matIndex].colors32;
                vertexCols[_firstVertexIndex] = color;
                vertexCols[_firstVertexIndex + 1] = color;
                vertexCols[_firstVertexIndex + 2] = color;
                vertexCols[_firstVertexIndex + 3] = color;
                if (apply) target.UpdateVertexData(TMP_VertexDataUpdateFlags.Colors32);
            }
 
            public void UpdateGeometry(TMP_Text target, Vector3 offset, Quaternion rotation, Vector3 scale, TMP_MeshInfo[] cachedMeshInfos, bool apply = true)
            {
                this.offset = offset;
                this.rotation = rotation;
                this.scale = scale;
 
                if (!apply) return;
 
                Vector3[] destinationVertices = _meshInfo.vertices;
                Vector3[] cachedVertices = cachedMeshInfos[_matIndex].vertices;
                destinationVertices[_firstVertexIndex] = cachedVertices[_firstVertexIndex + 0] - _charMidBaselineOffset;
                destinationVertices[_firstVertexIndex + 1] = cachedVertices[_firstVertexIndex + 1] - _charMidBaselineOffset;
                destinationVertices[_firstVertexIndex + 2] = cachedVertices[_firstVertexIndex + 2] - _charMidBaselineOffset;
                destinationVertices[_firstVertexIndex + 3] = cachedVertices[_firstVertexIndex + 3] - _charMidBaselineOffset;
                Matrix4x4 matrix = Matrix4x4.TRS(this.offset, this.rotation, this.scale);
                destinationVertices[_firstVertexIndex]
                    = matrix.MultiplyPoint3x4(destinationVertices[_firstVertexIndex + 0]) + _charMidBaselineOffset + _bottomLeftShift;
                destinationVertices[_firstVertexIndex + 1]
                    = matrix.MultiplyPoint3x4(destinationVertices[_firstVertexIndex + 1]) + _charMidBaselineOffset + _topLeftShift;
                destinationVertices[_firstVertexIndex + 2]
                    = matrix.MultiplyPoint3x4(destinationVertices[_firstVertexIndex + 2]) + _charMidBaselineOffset + _topRightShift;
                destinationVertices[_firstVertexIndex + 3]
                    = matrix.MultiplyPoint3x4(destinationVertices[_firstVertexIndex + 3]) + _charMidBaselineOffset + _bottomRightShift;
                _meshInfo.mesh.vertices = _meshInfo.vertices;
                target.UpdateGeometry(_meshInfo.mesh, _matIndex);
            }
 
            public void ShiftVertices(TMP_Text target, Vector3 topLeftShift, Vector3 topRightShift, Vector3 bottomLeftShift, Vector3 bottomRightShift)
            {
                _topLeftShift += topLeftShift;
                _topRightShift += topRightShift;
                _bottomLeftShift += bottomLeftShift;
                _bottomRightShift += bottomRightShift;
                Vector3[] destinationVertices = _meshInfo.vertices;
                destinationVertices[_firstVertexIndex] = destinationVertices[_firstVertexIndex] + _bottomLeftShift;
                destinationVertices[_firstVertexIndex + 1] = destinationVertices[_firstVertexIndex + 1] + _topLeftShift;
                destinationVertices[_firstVertexIndex + 2] = destinationVertices[_firstVertexIndex + 2] + _topRightShift;
                destinationVertices[_firstVertexIndex + 3] = destinationVertices[_firstVertexIndex + 3] + _bottomRightShift;
                _meshInfo.mesh.vertices = _meshInfo.vertices;
                target.UpdateGeometry(_meshInfo.mesh, _matIndex);
            }
 
            public void ResetVerticesShift(TMP_Text target)
            {
                Vector3[] destinationVertices = _meshInfo.vertices;
                destinationVertices[_firstVertexIndex] = destinationVertices[_firstVertexIndex] - _bottomLeftShift;
                destinationVertices[_firstVertexIndex + 1] = destinationVertices[_firstVertexIndex + 1] - _topLeftShift;
                destinationVertices[_firstVertexIndex + 2] = destinationVertices[_firstVertexIndex + 2] - _topRightShift;
                destinationVertices[_firstVertexIndex + 3] = destinationVertices[_firstVertexIndex + 3] - _bottomRightShift;
                _meshInfo.mesh.vertices = _meshInfo.vertices;
                target.UpdateGeometry(_meshInfo.mesh, _matIndex);
                _topLeftShift = _topRightShift = _bottomLeftShift = _bottomRightShift = Vector3.zero;
            }
        }
    }
 
    #endregion
}
#endif