Hello,
currently I’m working on a game with a lot of text which I display in a Textbox (TextMeshPro - Text UI). Because my text appears letter by letter it results in shifting a word in a new line if it has too many letters and I don’t like that effect. Therefore I try to check if a word gets truncated and if so, it gets moved by \n. Here the code:
// A segment is the full text of a text box. textSegments is the entire dialogue
foreach (string segment in textSegments)
{
string[] words = segment.Split();
string oldTextBoxText = TextBox.text;
foreach (string word in words)
{
TextBox.text += word;
TextBox.ForceMeshUpdate();
if ( TextBox.isTextTruncated ||
TextBox.textInfo.lineInfo[TextBox.textInfo.lineCount - 1].lastCharacterIndex
!= TextBox.textInfo.lineInfo[TextBox.textInfo.lineCount - 1].lastVisibleCharacterIndex)
{
// Correct the overflow by "reset" the text to the old state
TextBox.text = $"{oldTextBoxText}\n{word}";
}
else
TextBox.text += " ";
// Update the older textbox text to revert a word if its overflowing.
oldTextBoxText = TextBox.text;
}
}
This places the text word after word and checks if a letter is not visible (with IsTextTruncated and the lastVisibleCharacterIndex).
The problem here is, that if only one letter is missing it doesn’t detect that. Neither of the two recognize that.
Note: I wrote “somehow” seperated on purpose to demonstrate the problem. If I write it normally it works.
I tried also using a different Font Asset but it didn’t work. I’m working with the Version 3.0.6 of TextMeshPro and Unity 2020.3.21f1.
Do I miss something here?
