text hyperlink unity

// Check links in text void CheckLinks () {    Regex regx = new Regex ("((http://|https://|www\\.)([A-Z0-9.-:]{1,})\\.[0-9A-Z?;~&#=\\-_\\./]{2,})" , RegexOptions.IgnoreCase | RegexOptions.Singleline);     MatchCollection matches = regx.Matches (textMessage.text);     foreach (Match match in matches)        textMessage.text = textMessage.text.Replace (match.Value, ShortLink(match.Value));       }  // Cut long url string ShortLink (string link) {    string text = link;    int left = 9;       int right = 16;       string cut = "...";      if (link.Length > (left + right + cut.Length))        text = string.Format ("{0}{1}{2}", link.Substring (0, left), cut, link.Substring (link.Length - right, right));    return string.Format("<#7f7fe5><u><link=\"{0}\">{1}</link></u></color>", link, text); }

5
1
Cerulean 110 points

                                    // Get link and open page public void OnPointerClick (PointerEventData eventData) {    int linkIndex = TMP_TextUtilities.FindIntersectingLink (textMessage, eventData.position, eventData.pressEventCamera);    if (linkIndex == -1)        return;    TMP_LinkInfo linkInfo = textMessage.textInfo.linkInfo[linkIndex];  string selectedLink = linkInfo.GetLinkID();    if (selectedLink != &quot;&quot;) {       Debug.LogFormat (&quot;Open link {0}&quot;, selectedLink);    Application.OpenURL (selectedLink);            } }

5 (1 Votes)
0
Are there any code examples left?
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source