Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

TextMesh Pro TMP - Separate displayed text into lines with tags included

Discussion in 'UGUI & TextMesh Pro' started by nlp_eschipellite, Jun 21, 2023.

  1. nlp_eschipellite

    nlp_eschipellite

    Joined:
    Aug 2, 2017
    Posts:
    9
    Hey all,

    I'm currently looking to display some text in a test environment, and then separate the text by line for further evaluation.

    At the moment I assign the text, allow the text to refresh, and then check the TextInfo object for the resulting LineInfo array. This gives me a list of lines with information regarding the first and last character indices.

    In a simple setup, this does exactly what I am looking for and I can use the first and last character indices for each line to create a list of strings for each line. However, once tags are included (<b>, <i>, <u>, etc) things seem to get a bit more complicated. The CharacterInfo array does not include any of these tags, and therefore the character indices data in the LineInfo also does not reflect the addition of these tags. Therefore the character count shown is less than the actual character count with the tags included.

    Is there any way to get the actual character start / end indices including the tags for any given line?
     
  2. hwk9120

    hwk9120

    Joined:
    May 9, 2023
    Posts:
    15
    Hi,
    Assuming there is no spacing between tags, how about parse spacing using wordCount?
     
    nlp_eschipellite likes this.
  3. nlp_eschipellite

    nlp_eschipellite

    Joined:
    Aug 2, 2017
    Posts:
    9
    That's actually a partial alternative solution I've been working on.

    Each LineInfo does give me the word count, so I can sort of try and piece together which set of words should go on each line. I have a slight issue where splitting the entire string isn't giving me the exact same quantity as TMP though, but I can potentially figure that out since it likely has to do with splitting words between both spaces and new line breaks in a similar way that TMP does it.
     
    hwk9120 likes this.