Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
3
Question by FabienD · Feb 17, 2012 at 03:10 PM · textsizetextmeshwrapwrapping

How to calculate a TextMesh width without rendering it ?

Hi all,

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 ? Thanks !!!

Comment
Add comment · Show 3
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Owen-Reynolds · Feb 17, 2012 at 04:48 PM 2
Share

Have you played around with GUIstyle.CalcSize(new GUIContent("text here"));? I'd imagine there's some linear relationship between those pixel sizes and world sizes.

avatar image FabienD · Feb 17, 2012 at 04:58 PM 0
Share

Yep I tried with the GUIText but I haven't found a relationship on which I can rely yet. I may go further on this solution...

avatar image Bunny83 · Feb 17, 2012 at 05:37 PM 1
Share

I'm also quite sure there should be a linear relation between the size calculated for GUI and the resulting size of a textmesh since both use the font's size / kerning.

Just to be clear: We don't talk about the almost deprecated GUIText component. We talk about the UnityGUI class GUIStyle. Just create a style with your desired font / size and use GUIStyle.CalcSize to claculate the required size. Of course you have to find the scale between those pixel dimensions and world space width / height

2 Replies

· Add your reply
  • Sort: 
avatar image
4
Best Answer

Answer by FabienD · Feb 21, 2012 at 01:17 AM

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.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by Anxo · Feb 17, 2012 at 06:15 PM

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.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

8 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Wrapping a Textmesh text 5 Answers

Adjusting the transform width to match wrapped text (TextMeshPro) 0 Answers

Wrap text textmesh 0 Answers

UI Text: Wrap and Expand to keep aspect ratio 2 Answers

3D textmesh not being drawn properly in a 2D game 6 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges