Search Unity

  1. Improved Prefab workflow (includes Nested Prefabs!), 2D isometric Tilemap and more! Get the 2018.3 Beta now.
    Dismiss Notice
  2. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  3. Let us know a bit about your interests, and if you'd like to become more directly involved. Take our survey!
    Dismiss Notice
  4. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice
  5. Want to see the most recent patch releases? Take a peek at the patch release page.
    Dismiss Notice

TMP highlighting mouse over link

Discussion in 'Unity UI & TextMesh Pro' started by JohnHudeski, Aug 10, 2018.

  1. JohnHudeski

    JohnHudeski

    Joined:
    Nov 18, 2017
    Posts:
    85
    Hi, I am working with a paragraph with multiple links, a la news site with external references. I currently know how to click links and make them work but I can quite make the text render and underline

    I found this video but I can't find any such TMP_WordHighlighter


    And here is my horrible attempt at making it work. I can't even get it on the right index
    and the move over only works if the link is the first object the pointer hist when it enters the text collider

    Also, I don't think replacing strings this way is the way to go.
    Code (CSharp):
    1.  
    2.  
    3.     int lastIndex = -1;
    4.     string w, nw;
    5.     public void OnPointerEnter(PointerEventData eventData)
    6.     {
    7.         Debug.Log("Entered");
    8.         var newIndex = TMP_TextUtilities.FindIntersectingLink(textMessage, eventData.position, eventData.pressEventCamera);
    9.         if (newIndex == -1)
    10.             return;
    11.  
    12.         newIndex = TMP_TextUtilities.FindIntersectingWord(textMessage, eventData.position, eventData.pressEventCamera);
    13.         if (lastIndex == newIndex)
    14.             return;
    15.         lastIndex = newIndex;
    16.  
    17.         TMP_WordInfo wordInfo = textMessage.textInfo.wordInfo[lastIndex];
    18.         w = wordInfo.textComponent.text.Substring(wordInfo.firstCharacterIndex, wordInfo.characterCount);
    19.         nw = string.Format("<u><b>{0}</b></u>", w);
    20.         textMessage.text = textMessage.text.Replace(w, nw);
    21.         Debug.Log(w);
    22.     }
    23.  
    24.     public void OnPointerExit(PointerEventData eventData)
    25.     {
    26.         Debug.Log("Exited");
    27.         if (lastIndex == -1)
    28.             return;
    29.         textMessage.text = textMessage.text.Replace(nw, w);
    30.     }
    upload_2018-8-10_6-26-9.png
     
  2. Stephan_B

    Stephan_B

    Unity Technologies

    Joined:
    Feb 26, 2017
    Posts:
    1,734
    Take a look at example 12 and 12a included with TextMesh Pro. Especially, the scripts used in those examples. Those should help you get a better sense of it all.
     
    JohnHudeski likes this.
  3. JohnHudeski

    JohnHudeski

    Joined:
    Nov 18, 2017
    Posts:
    85
    Damn I feel stupid. Thanks
     
  4. Stephan_B

    Stephan_B

    Unity Technologies

    Joined:
    Feb 26, 2017
    Posts:
    1,734
    You are welcome and no worries. We have all been there many times ;)