Search Unity

  1. Get all the Unite Berlin 2018 news on the blog.
    Dismiss Notice
  2. Unity 2018.2 has arrived! Read about it here.
    Dismiss Notice
  3. We're looking for your feedback on the platforms you use and how you use them. Let us know!
    Dismiss Notice
  4. Improve your Unity skills with a certified instructor in a private, interactive classroom. Learn more.
    Dismiss Notice
  5. ARCore is out of developer preview! Read about it here.
    Dismiss Notice
  6. Magic Leap’s Lumin SDK Technical Preview for Unity lets you get started creating content for Magic Leap One™. Find more information on our blog!
    Dismiss Notice
  7. 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 at 1:22 PM.

  1. JohnHudeski

    JohnHudeski

    Joined:
    Nov 18, 2017
    Posts:
    75
    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,513
    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:
    75
    Damn I feel stupid. Thanks
     
  4. Stephan_B

    Stephan_B

    Unity Technologies

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