Skip to content

Commit f6a04a0

Browse files
committed
Refactor
1 parent 645b983 commit f6a04a0

2 files changed

Lines changed: 14 additions & 17 deletions

File tree

Assets/Hypertext/Examples/RegexHypertext.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public Entry(string regexPattern, Color color, Action<string> callback)
2424
}
2525

2626
/// <summary>
27-
/// 正規表現にマッチした部分文字列にクリックイベントを登録します
27+
/// 正規表現にマッチした部分文字列にクリックイベントリスナを登録します
2828
/// </summary>
2929
/// <param name="regexPattern">正規表現</param>
3030
/// <param name="onClick">クリック時のコールバック</param>
@@ -34,7 +34,7 @@ public void OnClick(string regexPattern, Action<string> onClick)
3434
}
3535

3636
/// <summary>
37-
/// 正規表現にマッチした部分文字列に色とクリックイベントを登録します
37+
/// 正規表現にマッチした部分文字列に色とクリックイベントリスナを登録します
3838
/// </summary>
3939
/// <param name="regexPattern">正規表現</param>
4040
/// <param name="color">テキストカラー</param>
@@ -58,7 +58,7 @@ public override void RemoveListeners()
5858
/// <summary>
5959
/// イベントリスナを追加します
6060
/// テキストの変更などでイベントの再登録が必要なときにも呼び出されます
61-
/// <see cref="HypertextBase.OnClick"/> を使ってクリックイベントを登録してください
61+
/// <see cref="HypertextBase.OnClick"/> を使ってクリックイベントリスナを登録してください
6262
/// </summary>
6363
protected override void AddListeners()
6464
{

Assets/Hypertext/Scripts/HypertextBase.cs

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ class Span
1717
public readonly Action<string> Callback;
1818
public List<Rect> BoundingBoxes;
1919

20-
public Span(int startIndex, int endIndex, Color color, Action<string> callback)
20+
public Span(int startIndex, int length, Color color, Action<string> callback)
2121
{
2222
StartIndex = startIndex;
23-
Length = endIndex;
23+
Length = length;
2424
Color = color;
2525
Callback = callback;
2626
BoundingBoxes = new List<Rect>();
@@ -52,7 +52,7 @@ const char
5252
Canvas RootCanvas => rootCanvas ?? (rootCanvas = GetComponentInParent<Canvas>());
5353

5454
/// <summary>
55-
/// 指定した部分文字列にクリックイベントを登録します
55+
/// 指定した部分文字列にクリックイベントリスナを登録します
5656
/// </summary>
5757
/// <param name="startIndex">部分文字列の開始文字位置</param>
5858
/// <param name="length">部分文字列の長さ</param>
@@ -88,8 +88,8 @@ public virtual void RemoveListeners()
8888

8989
/// <summary>
9090
/// イベントリスナを追加します
91-
/// テキストの変更などでイベントの再登録が必要なときにも呼び出されます
92-
/// <see cref="HypertextBase.OnClick"/> を使ってクリックイベントを登録してください
91+
/// テキストの変更などでイベントリスナの再登録が必要なときにも呼び出されます
92+
/// <see cref="HypertextBase.OnClick"/> を使ってクリックイベントリスナを登録してください
9393
/// </summary>
9494
protected abstract void AddListeners();
9595

@@ -154,8 +154,6 @@ protected override void OnPopulateMesh(VertexHelper toFill)
154154
}
155155
}
156156

157-
m_DisableFontTextureRebuiltCallback = false;
158-
159157
var vertices = verticesPool.Get();
160158
toFill.GetUIVertexStream(vertices);
161159

@@ -168,6 +166,8 @@ protected override void OnPopulateMesh(VertexHelper toFill)
168166
toFill.Clear();
169167
toFill.AddUIVertexTriangleStream(vertices);
170168
verticesPool.Release(vertices);
169+
170+
m_DisableFontTextureRebuiltCallback = false;
171171
}
172172

173173
void GenerateHrefBoundingBoxes(ref List<UIVertex> vertices)
@@ -181,9 +181,6 @@ void GenerateHrefBoundingBoxes(ref List<UIVertex> vertices)
181181
var startIndex = visibleCharIndexMap[span.StartIndex];
182182
var endIndex = visibleCharIndexMap[span.StartIndex + span.Length - 1];
183183

184-
startIndex = Mathf.Clamp(startIndex, 0, text.Length - 1);
185-
endIndex = Mathf.Clamp(endIndex, 0, text.Length - 1);
186-
187184
for (var textIndex = startIndex; textIndex <= endIndex; textIndex++)
188185
{
189186
var vertexStartIndex = textIndex * CharVerts;
@@ -312,7 +309,7 @@ void GenerateVisibleCharIndexMap(bool verticesReduced)
312309

313310
if (inTag)
314311
{
315-
offset++;
312+
offset--;
316313

317314
if (character == GreaterThan)
318315
{
@@ -321,15 +318,15 @@ void GenerateVisibleCharIndexMap(bool verticesReduced)
321318
}
322319
else if (supportRichText && character == LesserThan)
323320
{
324-
offset++;
321+
offset--;
325322
inTag = true;
326323
}
327324
else if (invisibleChars.Contains(character))
328325
{
329-
offset++;
326+
offset--;
330327
}
331328

332-
visibleCharIndexMap[i] = i - offset;
329+
visibleCharIndexMap[i] = Mathf.Max(0, i + offset);
333330
}
334331
}
335332

0 commit comments

Comments
 (0)