Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions Scripts/Runtime/TMProUGUIHyperlinks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,34 @@ public class TMProUGUIHyperlinks : MonoBehaviour, IPointerDownHandler, IPointerU
[Serializable]
public class LinkEvent : UnityEvent<string> { }

private const int RICH_TEXT_TAG_LENGTH_OVERRIDE = 1024;
private List<Color32[]> startColors = new List<Color32[]>();
private TextMeshProUGUI textMeshPro;
private Dictionary<int, bool> usedLinks = new Dictionary<int, bool>();
private int hoveredLinkIndex = -1;
private int pressedLinkIndex = -1;
private Camera mainCamera;

#if UNITY_EDITOR
[UnityEditor.InitializeOnLoadMethod]
#else
[RuntimeInitializeOnLoadMethod]
#endif
static void TryFixTMProTagLength()
{
// Fixing TMPro to have a bigger tag length. Currently it's just 128 which is peanuts - links can be very long.
// More specifically, the link tag breaks if the text inside the tag is longer than 128 chars, eg:
// For <link="http://..">
// <whatever_is_here_has_to_be_shorter_than_128_chars>
var fi = typeof(TMP_Text).GetField("m_htmlTag", BindingFlags.NonPublic | BindingFlags.Static);
var arr = fi.GetValue(null) as char[];
if (arr.Length < RICH_TEXT_TAG_LENGTH_OVERRIDE)
{
Array.Resize(ref arr, RICH_TEXT_TAG_LENGTH_OVERRIDE);
fi.SetValue(null, arr);
}
}

void Awake()
{
textMeshPro = GetComponent<TextMeshProUGUI>();
Expand Down