Skip to content

Fixed a bug that vertex information shifts #20

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions Assets/Scripts/EmojiText.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,33 @@ protected override void OnPopulateMesh(VertexHelper toFill)
return;
}

// Textは自動改行が入ると、改行コードの位置にもvertsの中に頂点情報が追加されるが、
// 自動改行が入らないと、改行コードのための頂点情報は無いので、Indexを調整する
if (emojiDic.Count > 0)
{
MatchCollection newLines = Regex.Matches(emojiText, "\\n");
// TextのRect範囲外は行(lineCount)にならないので、全文字が表示されている(characterCount)かも確認する。
if (cachedTextGenerator.lineCount == newLines.Count + 1 && emojiText.Length < cachedTextGenerator.characterCount)
{
// 絵文字があり、自動改行が入っていないので、indexを改行コードの数だけ調整する
Dictionary<int, EmojiInfo> emojiDicReplace = new Dictionary<int, EmojiInfo>();
foreach (var ed in emojiDic)
{
int index = ed.Key;
int offset = 0;
foreach (Match nl in newLines)
{
if (nl.Index < index)
{
offset -= 1;
}
}
emojiDicReplace.Add(index + offset, ed.Value);
}
emojiDic = emojiDicReplace;
}
}

Vector2 roundingOffset = new Vector2(verts[0].position.x, verts[0].position.y) * unitsPerPixel;
roundingOffset = PixelAdjustPoint(roundingOffset) - roundingOffset;
toFill.Clear();
Expand Down