Hello, everyone. I was wondering if there was a way to calculate the number of lines a string will be within a given width. The exact situation is I want the user to be able to type multiple lines into a text area and for the scroll view to adjust accordingly in length.
Hi,
Well, if you use String.Length , you can get the number of characters the string has. So, if the width of the text field is given, so just divide :)
Hope this can help you
GUIStyle.CalcHeight will give you the pixel height of the content (i.e. the string) if drawn at a certain width with the style.
That’s a pretty old question but I was browsing the scrollview tag. As it happen, I made a script for a chat. It splits strings instead of wrapping. That way, if you know the size of the SV and the height of a line, you only display those visible and can have 100k+ lines.
Anyway, the code : // This is the function using the split and sending it to the chatpublic void - Pastebin.com
Maybe it can help someone.