I am trying to fill a two lined dialogue box with a sentence. If that sentence were to be truncated, i.e. is too long for the dialogue box to display, I want to store the cut off words separately and display them in the next dialogue box.
To achieve that, I implement a do while loop adding one word at a time to the TextMeshProUGUI and checking if the current text is truncated or not. Unfortunately isTextTruncated always returns true in my case, thus exiting the do while loop after the first iteration. I am using FoceMeshUpdate as well as Canvas.ForceUpdateCanvases() to be safe, but it still doesn’t seem to work.
public void ParseWords(Dialog dialogue, int block)
{
Debug.Log("Starting conversation with " + dialogue.Name);
//Words.Clear();
Sentences.Clear();
string text = dialogue.SentenceBlock[block]; //text block to be separted into different sentences
var words = text.Split(new char[] { ' ' }, System.StringSplitOptions.RemoveEmptyEntries); //text block parsed into words
int counter = 0;
while(counter < words.Length)
{
DialogueText.text = "";
string sentence = "";
Debug.Log("is text truncated at beginning ?" + DialogueText.isTextTruncated); // is true
do {
if (counter >= words.Length) break;
sentence += words[counter] + " ";
DialogueText.text = sentence;
DialogueText.ForceMeshUpdate();
counter++;
Canvas.ForceUpdateCanvases();
} while (!DialogueText.isTextTruncated) ; // returns false, thus exiting the do while loop
Sentences.Enqueue(sentence);
Debug.Log(sentence);
}
// DisplayNextSentence();
}
One more thing, if I check isTextTruncated on awake on a random TextMeshProUGUI.text, it returns the expected bool, meaning that it does seem to work normally, but not in my loop.