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
3
Question by lackofwords · Nov 22, 2016 at 09:06 AM · textwindowalignmentaligntextarea

Text Alignment for Typing Effect

The Problem - Horizontal Word Bump
When creating a 'typing effect', where each text character appears one at a time, a word which reaches the horizontal max of a text field will exhibit a jump effect. Such that it begins to appear on Row1, but as soon as the next character of the word hits the horizontal max, it'll jump the entire word to Row2.

The correct typing effect should have the word begin on Row2 if the length of the word exceeds the horizontal max. Dynamically fitting any given changes to the size of the horizontal max.

The Current Solution - Context Size Fitter
Knowing the length of any given text isn't as trivial as it sounds. It isn't just the number of the characters in a given word, but also the font type, size, kerning, or any other text spacing can all affect how much space it actually takes up.

Digging around the Unity documentation, I couldn't really find anything besides the Content Size Fitter to determine whether or not a given word is fitting inside the text field.
https://docs.unity3d.com/Manual/script-ContentSizeFitter.html
That is the Content Size Fitter will help return the size of the text window regardless of Font Type Settings.

So to start, I have a Sentence with no newline formatting (line breaks) to it. A long sentence with no vertical blocks of whitespace.

I parse the Sentence into words, and then pass each word into the text field to determine the width. Such that, when each word is added it will increase the width of the Text Window (Content Size Fitter is set to Preferred Size with no min or max width).

Since the Text Window is growing in size when a word is added, all I have to do then is tell it where the Max Width is. And if the next word added hits or exceeds the Max Width, I then append a newline to the Sentence at that point.

What is returned (after the code is done running) is a formatted Sentence with newlines added such that it'll fit inside the given window parameters. So now with his New Sentence, the typing effect won't have the jarring effect of bumping a word to the next row.

The Flaw with this Solution
It isn't eloquent, the code requires to go through each and every single word in the Sentence. It needs to format the Sentence(s) before returning it back, which is then fed to the Typing Effect to display each character over time. You could imagine how costly this operation grows when it's formatting long paragraphs of sentences.

Content Size Fitter also requires a wait for the next frame to return the correct size of the Text Window. Such that, if you change the Text and call to get the Text Window width, it'll return the previous width oppose to the updated one.

Help - Suggestions
While it's possible to just hardcode every Sentence in, this comes at the cost of flexibility over overhead efficiency. Meaning, a person has to go over each and every single Sentence to see if it fits correctly in a given window size. Hardcoding also means you can't scale this to different Text Window Sizes. Meaning if the resolution changes, the hardcoded Sentence(s) wouldn't adjust to fit the new dimensions.

If you have any other ideas or approach to clean this up, I'll much appreciate the help. Thank you.

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

0 Replies

· Add your reply
  • Sort: 

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

How Does One Make TextMeshPro InputFields Scroll Appropriately When Their Text Components are Bottom-Aligned? 0 Answers

UI Text.LineSpacing doesn't work when the Text has only one line ? 1 Answer

Attach Text data to gameobjects by player 0 Answers

Read text from http 2 Answers

Creating a callout text for 3d object,Creating a callout UI text on object file in unity 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