Not sure how to even do that. But here is my whole Script for hyperlinks and such. This is attached to the TMP Text. When i run it in editor, it works fine and i can click the links. But when i run on device, it does nothing. The rest of the stuff works like if the text contains Congrats, itll play the animation.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using TMPro;
using System.Text.RegularExpressions;
using UnityEngine.EventSystems;
using SocialApp;
using UnityEngine.UI;
using System;
namespace SocialApp
{
[RequireComponent(typeof(TextMeshProUGUI))]
public class OpenHyperlinks : MonoBehaviour, IPointerClickHandler, IPointerDownHandler, IPointerUpHandler
{
[SerializeField]
private TextMeshProUGUI pTextMeshPro = default;
public FeedViewController FVC;
public Camera m_Camera;
public GameObject linkPanel;
public Text linkText;
public Text siteInfo;
public List<Sprite> _siteImages = new List<Sprite>();
public Image _siteImage;
public int siteID;
public Color _customRed;
public string _linkHandler;
public GameObject _gratePan;
public float _timer;
public bool _timerStarted = false;
public float _timerCopy;
public Animator _anim1, _anim2;
private void OnEnable()
{
_gratePan = GameObject.Find("GratsPanel");
m_Camera = GameObject.Find("Main Camera").GetComponent<Camera>();
_anim1 = GameObject.Find("GratsPanel/Panel/Image").GetComponent<Animator>();
_anim2 = GameObject.Find("GratsPanel/Panel/Image (1)").GetComponent<Animator>();
}
void Update()
{
if(_timerStarted)
{
_timer += Time.deltaTime;
if(_timer >= 0.2f)
{
_timer = 0;
FVC.LoadTextViewer();
_timerStarted = false;
}
}
}
public void OnPointerClick(PointerEventData eventData)
{
Debug.Log("TMP_LinkClickHandler.OnPointerClick(): Caught a click...");
Vector3 clickPosition = new Vector3(eventData.position.x, eventData.position.y, 0);
int linkIndex = TMP_TextUtilities.FindIntersectingLink (pTextMeshPro, eventData.position, eventData.pressEventCamera);
if (linkIndex == -1)
return;
TMP_LinkInfo linkInfo = pTextMeshPro.textInfo.linkInfo[linkIndex];
string selectedLink = linkInfo.GetLinkID();
if (selectedLink != "") {
Debug.LogFormat ("Open link {0}", selectedLink);
Application.OpenURL (selectedLink);
}
var wordIndex = TMP_TextUtilities.FindIntersectingWord(pTextMeshPro, clickPosition, m_Camera);
string LastClickedWord;
if (wordIndex != -1)
{
LastClickedWord = pTextMeshPro.textInfo.wordInfo[wordIndex].GetWord();
if(LastClickedWord.Contains("Grats"))
{
HandleGratsClick( );
}else if(LastClickedWord.Contains("Congrats"))
{
HandleGratsClick();
}else if(LastClickedWord.Contains("Congratulations"))
{
HandleGratsClick( );
}
}
}
public void OnPointerDown(PointerEventData eventData)
{
if(FVC._isLong)
{
_timerStarted = true;
}
}
public void OnPointerUp(PointerEventData eventData)
{
_timerStarted = false;
_timer = 0;
}
public void CheckText()
{
string s = FVC.LoadedFeed.BodyTXT;
if(s.Length > 300)
{
s = s.Substring(0, 300);
FVC._isLong = true;
FVC.TextBody.text = s += "<color=#DC143C><b>...See More</b></color>";
}else
{
FVC._isLong = false;
FVC.TextBody.text = FVC.LoadedFeed.BodyTXT;
}
if(AppManager.VIEW_CONTROLLER.DarkFeedObject.activeInHierarchy)
{
FVC.TextBody.color = Color.white;
}
}
public void HandleLinkClick(string inLinkID, string inLinkText, int LinkIndex)
{
Debug.Log("TMP_LinkClickHandler.HandleLinkClick(): Link ID #" + inLinkID + " clicked!");
// Be aware of the injection attack ramifications of using this function:
// https://docs.unity3d.com/ScriptReference/Application.OpenURL.html
Application.OpenURL(_linkHandler);
}
public void HandleGratsClick()
{
_gratePan.GetComponent<Canvas>().sortingOrder = 100;
Debug.Log("TMP_LinkClickHandler.HandleLinkClick(): Link ID #" + " clicked!");
_anim1.SetBool("PlayStar", true);
_anim2.SetBool("PlayStar", true);
}
public void CheckLinkMessagesComments(string input, Action<string> _callback)
{
Regex regx = new Regex("((http://|https://|www\\.)([A-Z0-9.-:]{1,})\\.[0-9A-Z?;~&#=\\-_\\./]{2,})", RegexOptions.IgnoreCase | RegexOptions.Singleline);
MatchCollection matches = regx.Matches(input);
foreach (Match match in matches)
{
input = input.Replace(match.Value, ShortLink(match.Value));
UnityMainThreadDispatcher.Instance().Enqueue(() => _callback.Invoke(input));
}
}
public void CheckGrats()
{
var inputStr = pTextMeshPro.text;
var pieces = inputStr.Split(' ', '.'); // consider \n as well if this is multiline
var result = string.Empty;
for (int i = 0, j = 0; i < pieces.Length; i++, j++)
{
j += pieces[i].Length;
if (pieces[i].Contains("Congratulations"))
{
pieces[i] = $"<color=#8A2BE2><b>{pieces[i]}</b></color>";
}else if(pieces[i].Contains("Grats"))
{
pieces[i] = $"<color=#8A2BE2><b>{pieces[i]}</b></color>";
}else if(pieces[i].Contains("Congrats"))
{
pieces[i] = $"<color=#8A2BE2><b>{pieces[i]}</b></color>";
}
result = string.Concat(result, pieces[i]);
if (i < pieces.Length - 1) result = string.Concat(result, inputStr[j]); // don't forget to stitch your actual delimiter back
pTextMeshPro.text = result.ToString();
}
}
public void CheckHash()
{
var inputStr = pTextMeshPro.text;
var pieces = inputStr.Split(' ', '.'); // consider \n as well if this is multiline
var result = string.Empty;
for (int i = 0, j = 0; i < pieces.Length; i++, j++)
{
j += pieces[i].Length;
if (pieces[i].StartsWith("#")) pieces[i] = $"<color=#DC143C><b>{pieces[i]}</b></color>";
result = string.Concat(result, pieces[i]);
if (i < pieces.Length - 1) result = string.Concat(result, inputStr[j]); // don't forget to stitch your actual delimiter back
pTextMeshPro.text = result.ToString();
}
}
public void CheckNameSpace()
{
var inputStr = pTextMeshPro.text;
var pieces = inputStr.Split(' ', '.'); // consider \n as well if this is multiline
var result = string.Empty;
for (int i = 0, j = 0; i < pieces.Length; i++, j++)
{
j += pieces[i].Length;
if (pieces[i].StartsWith("@")) pieces[i] = $"<color=#00CED1><b>{pieces[i]}</b></color>";
result = string.Concat(result, pieces[i]);
if (i < pieces.Length - 1) result = string.Concat(result, inputStr[j]); // don't forget to stitch your actual delimiter back
pTextMeshPro.text = result.ToString();
}
}
public void ClickLinkOpen()
{
Regex regx = new Regex("((http://|https://|www\\.)([A-Z0-9.-:]{1,})\\.[0-9A-Z?;~&#=\\-_\\./]{2,})", RegexOptions.IgnoreCase | RegexOptions.Singleline);
MatchCollection matches = regx.Matches(pTextMeshPro.text);
foreach(Match match1 in matches)
{
Application.OpenURL(_linkHandler);
}
}
public 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(pTextMeshPro.text);
foreach (Match match in matches)
pTextMeshPro.text = pTextMeshPro.text.Replace (match.Value, ShortLink(match.Value));
}
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("<#FF5C65FF><u><link=\"{0}\">{1}</link></u></color>", link, text);
}
}
}