Search Unity

TextMesh Pro Get characters in specific style in TextMeshPro

Discussion in 'UGUI & TextMesh Pro' started by dadude123, Jan 25, 2018.

  1. dadude123

    dadude123

    Joined:
    Feb 26, 2014
    Posts:
    789
    I'm using the VertexJitter.cs example as a base and one thing I want to do is to only apply my changes to characters that are inside a specific style.

    I already added a style to the "TMP Default Style Sheet" asset and it recognizes it.

    But now while iterating over the characters, I don't see any way in TMP_TextInfo to get the styles that are used in the current text (or their names and start and end index).

    There is fontStyles but that doesn't help me since I'm not looking for <u>, <i>, ...I need to find <style=MyStyle>

    Do I have to manually parse the text? :(
    Maybe I'm going about this the wrong way and there's an easier way to simply have a tag and apply custom modifications to it? I mean having a custom style and doing stuff to the characters inside it sounds pretty common at least.
    Or does a newer version have something like textInfo.Tags, textInfo.Styles, ... or so?
     
    Last edited: Jan 25, 2018
  2. dadude123

    dadude123

    Joined:
    Feb 26, 2014
    Posts:
    789
    I figured out that I can just abuse <link> tags for now because that has linkInfo and .linkTextfirstCharacterIndex
    Maybe this will cause problems further down the line though because I want to use my style inside links as well, but for now it works just fine.

    If anyone knows a better way please let me know :)
     
  3. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    Styles tags was can end up being a combination of rich text tags, characters and even other style tags are not tracked in the characterInfo[].

    Using the link tag which provides for some generic way to identify / track portions of the text, is actually well suited for this.
     
    dadude123 likes this.