Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Text Group?

Discussion in 'UGUI & TextMesh Pro' started by mog-mog-mog, Oct 6, 2014.

  1. mog-mog-mog

    mog-mog-mog

    Joined:
    Feb 12, 2014
    Posts:
    266
    I've multiple Text UI elements with "Best Fit" enabled in my scene. I would like all to have same font size = Minimum of all Text elements. I want them to take the Best Fit Font size of longest length item. What are my options here? Is there anything like Text Group where all Text elements maintain same size?
     
  2. mog-mog-mog

    mog-mog-mog

    Joined:
    Feb 12, 2014
    Posts:
    266
  3. Marble

    Marble

    Joined:
    Aug 29, 2005
    Posts:
    1,268
    I suppose you'll have to use a script to iterate through all the Text elements, find the longest item, then set all other elements to that value?
     
  4. mog-mog-mog

    mog-mog-mog

    Joined:
    Feb 12, 2014
    Posts:
    266
    I tried that approach, but it won't work. Because best-fit enabled keep updating the text size. Also font-size returned is always the default font size and not the best fit font size.
     
  5. Marble

    Marble

    Joined:
    Aug 29, 2005
    Posts:
    1,268
    Hm. That's disappointing. Perhaps you should file that issue with Best Fit as a bug. You need a way to get the text's real current size, obviously, to do anything. I don't think the UI currently has any premade concept of "groups" as you mean it.
     
  6. leo-carneiro

    leo-carneiro

    Unity Technologies

    Joined:
    Sep 1, 2011
    Posts:
    49
    You can access the Best Fit font size used on a Text component with something like this:
    textComponent.cachedTextGenerator.fontSizeUsedForBestFit

    It's in our to-do list to write docs for this one still.

    Hope this helps.
     
    mog-mog-mog and Marble like this.
  7. mog-mog-mog

    mog-mog-mog

    Joined:
    Feb 12, 2014
    Posts:
    266
    Thank you, Finally I am able to make a working simple solution. I'll add it to wiki, thanks