Skip to content

Commit 01da453

Browse files
authored
Merge pull request #1 from nkjzm/update-for-unity2019
Untiy2019のText描画における頂点数の仕様変更に対する修正
2 parents b93b53d + e00b6e6 commit 01da453

1 file changed

Lines changed: 18 additions & 0 deletions

File tree

Assets/Hypertext/Examples/RegexHypertext.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.Linq;
34
using System.Text.RegularExpressions;
45
using UnityEngine;
56

@@ -62,11 +63,28 @@ public override void RemoveListeners()
6263
/// </summary>
6364
protected override void AddListeners()
6465
{
66+
var lineCount = text.Count(x => x == '\n') + 1;
67+
bool hasFolded = lineCount != cachedTextGenerator.lineCount;
68+
6569
foreach (var entry in entries)
6670
{
6771
foreach (Match match in Regex.Matches(text, entry.RegexPattern))
6872
{
73+
#if UNITY_2019_1_OR_NEWER
74+
if (hasFolded)
75+
{
76+
OnClick(match.Index, match.Value.Length, entry.Color, entry.Callback);
77+
}
78+
else
79+
{
80+
// 折り返していない場合のみ「空白」と「改行」が描画されないため、調整する
81+
var head = text.Substring(0, match.Index);
82+
var count = head.Count(x => x == ' ') + head.Count(x => x == '\n');
83+
OnClick(match.Index - count, match.Value.Length, entry.Color, entry.Callback);
84+
}
85+
#else
6986
OnClick(match.Index, match.Value.Length, entry.Color, entry.Callback);
87+
#endif
7088
}
7189
}
7290
}

0 commit comments

Comments
 (0)