Elin Decompiled Documentation EA 23.102 Nightly
Loading...
Searching...
No Matches
LimitVisibleCharacters.cs
Go to the documentation of this file.
1using System.Collections;
2using System.Collections.Generic;
3using System.Text.RegularExpressions;
4using UnityEngine;
5using UnityEngine.UI;
6
7[AddComponentMenu("UI/ToJ Effects/Limit Visible Characters", 8)]
8[RequireComponent(typeof(Text))]
9public class LimitVisibleCharacters : BaseMeshEffect
10{
11 private const string REGEX_TAGS = "<b>|</b>|<i>|</i>|<size=.*?>|</size>|<color=.*?>|</color>|<material=.*?>|</material>";
12
13 [SerializeField]
15
16 private List<UIVertex> m_Verts = new List<UIVertex>();
17
19 {
20 get
21 {
23 }
24 set
25 {
26 if (m_VisibleCharacterCount != value)
27 {
29 if (base.graphic != null)
30 {
31 base.graphic.SetVerticesDirty();
32 }
33 }
34 }
35 }
36
38 {
39 }
40
41 public override void ModifyMesh(VertexHelper vh)
42 {
43 if (!IsActive())
44 {
45 return;
46 }
47 vh.GetUIVertexStream(m_Verts);
48 Text component = GetComponent<Text>();
49 List<UIVertex> list = new List<UIVertex>();
50 IEnumerator enumerator = null;
51 Match match = null;
52 string text = component.text.Substring(0, component.cachedTextGenerator.characterCountVisible);
53 int lengthWithoutTags = text.Length;
54 if (component.supportRichText)
55 {
56 enumerator = GetRegexMatchedTags(text, out lengthWithoutTags).GetEnumerator();
57 match = null;
58 if (enumerator.MoveNext())
59 {
60 match = (Match)enumerator.Current;
61 }
62 }
63 if (visibleCharacterCount >= lengthWithoutTags)
64 {
65 return;
66 }
67 int num = 0;
68 while (list.Count < visibleCharacterCount * 6)
69 {
70 bool flag = false;
71 if (component.supportRichText && match != null && match.Index == num)
72 {
73 num += match.Length - 1;
74 match = null;
75 if (enumerator.MoveNext())
76 {
77 match = (Match)enumerator.Current;
78 }
79 flag = true;
80 }
81 if (!flag)
82 {
83 for (int i = 0; i < 6; i++)
84 {
85 UIVertex item = m_Verts[num * 6 + i];
86 list.Add(item);
87 }
88 }
89 num++;
90 }
91 vh.Clear();
92 vh.AddUIVertexTriangleStream(list);
93 }
94
95 private MatchCollection GetRegexMatchedTags(string text, out int lengthWithoutTags)
96 {
97 MatchCollection matchCollection = Regex.Matches(text, "<b>|</b>|<i>|</i>|<size=.*?>|</size>|<color=.*?>|</color>|<material=.*?>|</material>");
98 lengthWithoutTags = 0;
99 int num = 0;
100 foreach (Match item in matchCollection)
101 {
102 num += item.Length;
103 }
104 lengthWithoutTags = text.Length - num;
105 return matchCollection;
106 }
107}
MatchCollection GetRegexMatchedTags(string text, out int lengthWithoutTags)
override void ModifyMesh(VertexHelper vh)