超链接书写标记
<link="ID">my link</link>
Canvas渲染模式选择:
挂载脚本:
using System.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
using UnityEngine.EventSystems;
public class TestClickRichText : MonoBehaviour, IPointerClickHandler
{
public TextMeshProUGUI text;
public void OnPointerClick(PointerEventData eventData)
{
Vector3 pos = new Vector3(eventData.position.x, eventData.position.y, 0);
int linkIndex = TMP_TextUtilities.FindIntersectingLink(text, pos, null); //--UI相机
if (linkIndex > -1)
{
TMP_LinkInfo linkInfo = text.textInfo.linkInfo[linkIndex];
Debug.Log(linkInfo.GetLinkText());
//Application.OpenURL(linkInfo.GetLinkID());
}
}
}
最后如果渲染模式是其他的并且指定了渲染相机那么代码这么修改:
(需要传入渲染相机)
int linkIndex = TMP_TextUtilities.FindIntersectingLink(text, pos, Camera.main); //--UI相机
参考博客:
https://blog.csdn.net/a962035/article/details/108224498
https://www.cnblogs.com/zhaoqingqing/p/7471696.html