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. Dismiss Notice

Custom Rich Text in TextMesh Pro

Discussion in 'UGUI & TextMesh Pro' started by BlockFade, Jun 10, 2017.

  1. BlockFade

    BlockFade

    Joined:
    Jan 28, 2017
    Posts:
    25
    Im making a engine for making undertale games!
    But I need the ability to add custom rich text in Text Mesh Pro, as in <pause> to pause the text type effect I have for a moment!
    Please help!
     
  2. Stephan_B

    Stephan_B

    Unity Technologies

    Joined:
    Feb 26, 2017
    Posts:
    6,588
    I guess users who have access to the source code version of TMP could modify the Rich Text parsing to add simple tags.

    I would suggest reaching out to your Unity sales representative if you do not have access to the source code version of TMP.
     
  3. BlockFade

    BlockFade

    Joined:
    Jan 28, 2017
    Posts:
    25
    Okay, Thanks.
     
  4. celinedrules

    celinedrules

    Joined:
    Jan 31, 2013
    Posts:
    16
    I know this is an old post but I did find a solution to add a pause tag into the typing text.

    In the file TMP_RichTextTagStack.cs add:

    Code (CSharp):
    1. public struct TMP_PauseStack
    2. {
    3.      public int charPos;
    4.      public float pauseTime;
    5. }
    Then in the file TMP_Text.cs add:

    Code (CSharp):
    1. // Pause Tags
    2. public TMP_RichTextTagStack<TMP_PauseStack> pauseStack =
    3.    new TMP_RichTextTagStack<TMP_PauseStack>(
    4.       Enumerable.Repeat(new TMP_PauseStack { charPos = -1, pauseTime = 0 },
    5.          16).ToArray());
    In the same file modify the switch statement

    Code (CSharp):
    1. switch (m_xmlAttribute[0].nameHashCode)
    and add:

    Code (CSharp):
    1. case 308822:  // <Pause>
    2.    foreach(TMP_PauseStack ps in pauseStack.m_ItemStack)
    3.       if (ps.charPos == m_characterCount)
    4.          return true;
    5.                    
    6. TMP_PauseStack newPauseStack = new TMP_PauseStack
    7. {
    8.    charPos = m_characterCount,  pauseTime = ConvertToFloat(m_htmlTag,
    9.       m_xmlAttribute[0].valueStartIndex, m_xmlAttribute[0].valueLength)
    10. };
    11.  
    12. pauseStack.Add(newPauseStack);
    13.                    
    14. return true;
    Note that 308822 is going to be the custom hashcode for your specific tag.

    In your custom typing script you can then access the position of the pause tag as well as the duration like this:

    Code (CSharp):
    1. foreach(TMP_PauseStack ps in textMeshPro.pauseStack.m_ItemStack)
    2. {
    3.    int pausePos = ps.charPos;
    4.    float pauseTime = ps.pauseTime;
    5. }
    Example TextMeshPro Text would then look something like this:

    Code (CSharp):
    1. THE LAST METROID IS IN CAPTIVITY. <pause=3>THE GALAXY IS AT PEACE . . . <pause=10>
     
  5. OverGast

    OverGast

    Joined:
    Aug 8, 2015
    Posts:
    24
    Hey I know this post is kinda old, but the above answer doesnt seems to work for me. I dont have any file called TMP_RichTextTagStack.cs but i do have TMP_RichTextTagsCommon.cs.

    Any help with this?