I am trying to create a wrapping function for TextMeshes. I want it to be based on a maximum width from the global world.
To do so I think I need to know how wide a letter or a word will be in the world. Right now I can get this by rendering it temporarily and use the bounds.size property of the renderer. For better performances, I would prefer to be able to calculate this width without rendering the text, knowing the various TextMesh attributes.
Someone wanted to use the planes generated by the TextMesh to do so, but it sounds to be impossible via this method.
(Other thread regarding the TextMesh wrapping without answer.)
Does anybody have an idea ?
I will answer myself, or kind of…
Thanks to the orientation from Owen Reynolds and Bunny83 I was able to establish the size factor linking the GUIContent and a TextMesh.
It is safe to assume for a font-size greater than 10 that the factor is 0.1. Example :
For a text rendered using a GUIContent which has a width of 507 pixels, the size of the same text rendered using a TextMesh with the same style will have a width (Bounds.size) of 50.7 units.
Using this factor, I have got now a 3D Text (TextMesh) wrapper which is working well !
A good thing to do will be to test this using various fonts…
Thanks very much for your help guys.
Use the same method you are using now, but instead, when you create the text assign it (via script or by prefab settings) to a layer that is ignored by the camera. If you at some point wanted to show the text, you can then change its layer.