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
1
Question by Youngapprentice · Dec 17, 2011 at 08:41 PM · guistringscrollsimple

Sensing if a string is multi - lined

Hi, all! I am creating a conversation system, and it is going along quite well. I was wondering if anyone knew how to sense if a string is longer than the space it is contained in. I have a box that is high enough for one line of text across it, and if the string is too long, it runs off the box. I need to make a script that checks to see if the supplied string is longer than x amount of characters, and if so, pop an old school scrollbar on there. I'm pretty sure I can achieve the scroll bar with two buttons and a GUI group, but I would like to know how to sense if a string is multi-lined.

Some images if I'm not being clear here. the first is text that fits, and the second is text that doesn't.

alt text alt text

Comment
Add comment · Show 1
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 Statement · Dec 18, 2011 at 12:18 PM 0
Share

I would be a bit nervous saying "Do I know you?" to a green entity with a rifle next to his hand. :) Cool pics, and helpful ones too.

2 Replies

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

Answer by flamy · Dec 17, 2011 at 08:50 PM

you can get the length of the string using "Length" property

it works like stringName.Lenghth;

u can calculate the number of character that can contain in the bar using its width and height along with the the size of the font you are using!

so just compare it and u would get what you want!!

Comment
Add comment · Show 8 · 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 jahroy · Dec 17, 2011 at 11:18 PM 1
Share

The length of the string doesn't help you deter$$anonymous$$e its size (in pixels) when drawn with the GUI.

You need to use GUIStyle.CalcSize to relate the string to the GUIStyle and rectangle.

avatar image flamy · Dec 18, 2011 at 12:41 AM 0
Share

oh i dont think so anyway GUIStyle.CalcSize would make it easy!!

u could get size in pixels by multiplying the font size u r using to draw the font with the strlen!!

avatar image Youngapprentice · Dec 18, 2011 at 03:16 AM 0
Share

But if the font is size 24, does that mean it is 24 pixels by 24 pixels? If so, the math would suggest that if I have a box that is 350 wide, I could fit fourteen characters across it, when I can actually fit 26.

avatar image jahroy · Dec 18, 2011 at 03:46 AM 0
Share

I would guess the CalcSize and CalcHeight functions exist to save us programmers the headache of considering all the little factors that come into play when mapping a character and a font to a pixel size.

I would imagine there are factors like the spacing between the characters and the style that must come into play.

It's probably similar to the way that GUILayout takes care of all kinds of factors that are a pain in the butt to consider manually (like borders, margins, scrollbars, etc...).

avatar image Youngapprentice · Dec 18, 2011 at 04:15 AM 0
Share

So how would I go about using them? I looked them up in the script reference and I am CLUELESS

Show more comments
avatar image
1

Answer by Statement · Dec 17, 2011 at 10:24 PM

Maybe you could use GUIStyle.calcSize? to figure out how large space the text with a given style need? And the scrollbar can be automatic with GUI.BeginScrollView. That is, if you use UnityGUI..

Comment
Add comment · Show 1 · 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 Youngapprentice · Dec 17, 2011 at 10:47 PM 0
Share

Really? Thanks! I'll try the scroll bar and see if I like it ;)

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

7 People are following this question.

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

Related Questions

GUI Scroll View 1 Answer

String not showing up in GUI label 1 Answer

Scrolling Text 1 Answer

How to output a file to a single string? 1 Answer

I need help with my pause menu 1 Answer


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