Search Unity

TextMesh Pro still only one Style Sheet for the whole project?

Discussion in 'UGUI & TextMesh Pro' started by JoeStrout, Mar 3, 2019.

  1. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,859
    I have need to define styles for various source code tokens (comments, string literals, keywords, etc.). But I may need these to display differently in different contexts (e.g., a code editor vs. an onscreen help area), even at the same time.

    Style sheets would seem like the perfect solution, except that it appears TMPro supports only one style sheet for the whole project, which makes it a useless feature (to me).

    Is this limitation still there in the latest version? If only I could override the style sheet on a per-TextMeshProUGUI basis, it would be ideal. So much so, that I'd be willing to move to the bleeding-edge release of Unity if necessary to get it!
     
    mandisaw likes this.
  2. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    This functionality is not currently available but sort of has been requested previously. As such and given I was planning on making some unrelated tweaks to Style Sheets, I'll take a closer look at this feature request.

    I am assuming that similar to how <sprite=0> will use the sprite at index = 0 of either the sprite asset assigned to an individual text object or in the absence of one use the sprite at index = 0 of the default sprite asset assigned in the TMP Settings that you would like the same functionality to be available with Style Sheets where using something like <style="H1"> will use the style from a style sheet assigned to a text object or in the absence of one, use the style from the default style sheet assigned in the TMP Settings. Correct?
     
    mandisaw and JoeStrout like this.
  3. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,859
    Yes, that sounds perfect!
     
  4. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    Made additional improvements in regards to Style Sheets and Styles where a Text Style can now be defined per text object.

    upload_2019-3-12_0-3-16.png

    The Text Styles listed include those from the potential Style Sheet assigned to the text object as well as those from the Style Sheet assigned in the TMP Settings.

    In the event a style (same name) is contained in both the local style sheet and global style sheet defined in the TMP Settings, then the local style will override the global style.

    By default text objects use the "Normal" Text Style which is no style at all.

    It is possible to combine Text Styles with Styles defined in the text. Text Styles are applied before and after any styles contained in the text itself.

    I also improved handling of nested tags.

    Given the Style Sheet as seen below using the following text "<style="Q1">A</style>"

    upload_2019-3-11_23-58-20.png

    which displays the following text.

    upload_2019-3-11_23-59-1.png
     
    Last edited: Mar 12, 2019
    AdamBebkoFV, mandisaw and JoeStrout like this.
  5. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,859
    Sounds perfect, thank you Stephan!
     
  6. MicroEyes

    MicroEyes

    Joined:
    Jul 3, 2012
    Posts:
    309

    Hi Stephan,
    I was look for exactly this support to assign a style to a text object instead of defining style tag in every text object. But i couldn't find the above fields, Text Style and Style Sheet Asset in TMP v1.4.1 or v2.0.1.

    When will this feature be available?

    I have a case in which my game contains lots of text objects, which as split into 4 styles depends on font size, color and style. That's why i need the above feature.
     
  7. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    New TMP package (version 1.5.0-preview.1) should be available this week.
     
    JoeStrout likes this.
  8. MicroEyes

    MicroEyes

    Joined:
    Jul 3, 2012
    Posts:
    309
    Perfect. I am looking forward to the new version.
     
  9. Numa

    Numa

    Joined:
    Oct 7, 2014
    Posts:
    100
    That's awesome, looking forward to this update!
     
  10. Numa

    Numa

    Joined:
    Oct 7, 2014
    Posts:
    100
  11. xuanyusong

    xuanyusong

    Joined:
    Apr 10, 2013
    Posts:
    49
    TMP package (version 2.0.1) do not have this features :(
     
  12. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    Latest release is version 2.1.0-preview.2 which includes this feature.
     
    clueduppstephen likes this.
  13. clueduppstephen

    clueduppstephen

    Joined:
    Aug 6, 2019
    Posts:
    12
    Great work on this feature, I do wonder if there is a way to dynamically change the Style Sheet Asset at runtime. We have different game modes that share modal UIs, and we would like to change the Style sheet in different game modes so we can reuse the text copy without having to change the style tags.
     
  14. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    It is currently possible to assign a local style per text object. As such, you can assign a new style sheet as needed.

    It is not currently possible to change / assign a new global style sheet in the TMP Settings but I can revise that for the next release.
     
    clueduppstephen likes this.
  15. tobias_froihofer

    tobias_froihofer

    Joined:
    Jul 30, 2015
    Posts:
    56
    Is it possible to reference a style sheet within a style tag, similar to how we can reference a sprite asset?

    For sprite assets I can use <sprite="NameOfSpriteAsset" name="NameOfSprite>.
    Is there something similar to this for the style tag, like <style="NameOfStyleSheet" name="NameOfStyle">? I can't find anything in the documentation about it, but this would be really nice to have as we could more easily switch between styles via code.
     
  16. Buzzrick_Runaway

    Buzzrick_Runaway

    Joined:
    Jan 7, 2018
    Posts:
    18
    I realise that this thread is a bit old now, but I wanted to throw my comments in as well.

    It would be very useful to be able to change the global style sheet in the TMP settings at runtime. The scenario that I'm trying to work through is, we're leaning heavily into using TMPro Styles, and I want to be able to replace the stylesheet out for each language, and in the styles the font relevant to each language would be specified.