Pretty straight-forward question. I want to recognize when the text begins to overflow in a Text component of the canvas UI system through c# scripting. The idea is to write text to a page, recognize when it’s reached the end of the page, and start writing on another page.
Updates:It appears I can access the appropriate information I need through a TextGenerator:
So after some experimentation, this doesn’t quite work. I was hoping that the cached TextGenerator would give more information regarding the vertical overflow truncation, instead it seems that the characterCount and characterCountVisible come out to the same value. How can I recognize the truncated segment of text?
Bump: Really having an issue finding a working solution, any input welcomed.
The idea is to write text to a page, recognize when it’s reached the end of the page, and start writing on another page.
Bump: Anyone have any answers? I think I have a concept to go with - I want to grab the characters being drawn by the TextGenerator. Anyone know how to convert a UICharInfo List into a string? For instance - the characters array on TextGenerator.
Bump: Who would of thought this would be such a difficult task to accomplish?
Maybe textComponent.cachedTextGenerator.characterCountVisible could help.
But make sure a frame has passed after you assign the text, or use Canvas.ForceUpdateCanvases(); to have the real values from the cachedTextGenerator.
And compare it to textComponent.text.length.
Having the same kind of issue with a chat addition, I’m going to have to say cachedTextGenerator won’t be much help to you, and heres why. When I tested it, and checked it, wrong info, ran it again, it would correct. Its not that it doesn’t have the right info, its that it doesn’t seem to refresh as you need it, so its information can’t be counted on…
What I ended up doing is going with mono spaced fonts so I could keep up with the position based on string length (OH GOD NO!!!) yea, but they have more variation then they used to have so I tried to compensate by having a selector that lets you choose which font it uses. =p
best of luck, no its not at ALL what you were looking for, and for that I apologize, but its the best answer I found in the same position.
I needed this for RTL languages, and I came up with another way.
Disclaimer: I gave up on making the app in Unity, and used Android studio instead.
You can check the width of every letter, and compare it to the width of the text component.
You can get that from Font, in the text component.
I’m afraid Unity is greatly lacking in text manipulation at the moment… especially for mobile.