Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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
2
Question by Llorens Marti Garcia · Feb 11, 2010 at 11:15 AM · guitextguilayout

How do i get size in pixels of a GUI.Label for chat construction purpose ?

Hi

I am designing a chat system where i will write to the screen all the text that comes from net.

I need to be able to write lines of text with diferent colors, etc. I want to cut the entrance string and write in screen with GUI.Label with diferent fonts and/or colors. But i dont know how to know how many pixels will have the string in the destination label.

I know that in DX there is a function that makes a fake render of the text you want to write and returns you the destination size (width and height) of the rendered text before you render it.

With this, i will be able to cut long strings and make new lines.

Finally i will control how many lines user can view without GUILayout interaction.

So, the question is: Is there any function or methodology to get how many pixels a rendered string will size ?

I can't bypass it by count characters and have a maximum characters lenght, but 'i' cahracter doesnt have the same size as 'a' character.

Thanks for your time :)

LLORENS

Comment
Add comment
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

2 Replies

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

Answer by Mike 3 · Jun 03, 2010 at 05:44 PM

You can use the helper functions in GUIStyle to find the size of content

http://unity3d.com/support/documentation/ScriptReference/GUIStyle.html

Functions you may want to look at: http://unity3d.com/support/documentation/ScriptReference/GUIStyle.CalcSize.html http://unity3d.com/support/documentation/ScriptReference/GUIStyle.CalcScreenSize.html http://unity3d.com/support/documentation/ScriptReference/GUIStyle.CalcHeight.html http://unity3d.com/support/documentation/ScriptReference/GUIStyle.CalcMinMaxWidth.html

If you're not using a specific GUIStyle, you can just use something like this (in c#)

GUIStyle style = "Label";

Which will assign the Label style from the currently used skin

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
1

Answer by jonas-echterhoff · Feb 11, 2010 at 12:35 PM

Why don't you want to use GUILayout? If you do, you can get the size of an element using the GUILayoutUtility.GetRect method.

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

No one has followed this question yet.

Related Questions

Default text / Already written text on GUI Text Field. 1 Answer

Can't add a GUI in C#?? 1 Answer

Similar function in UI for GUILayoutUtility.GetRect 0 Answers

How can I add "..." to GUI.Label if it goes past its bounds? 1 Answer

Checking 2 string variables 0 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