| | 1 | | using System; |
| | 2 | | using TMPro; |
| | 3 | | using UnityEngine; |
| | 4 | | using UnityEngine.EventSystems; |
| | 5 | |
|
| | 6 | | namespace UIComponents.Scripts.Components.Text |
| | 7 | | { |
| | 8 | | public class TMPTextHyperLink : MonoBehaviour, IPointerClickHandler |
| | 9 | | { |
| | 10 | | [SerializeField] private TMP_Text tmpTextBox; |
| | 11 | | [SerializeField] private Canvas canvasToCheck; |
| | 12 | |
|
| | 13 | | private Camera cameraToUse; |
| | 14 | |
|
| | 15 | | public event Action HyperLinkClicked; |
| | 16 | |
|
| | 17 | | private void Awake() |
| | 18 | | { |
| 13 | 19 | | cameraToUse = canvasToCheck.renderMode == RenderMode.ScreenSpaceOverlay ? null : canvasToCheck.worldCamera; |
| 13 | 20 | | } |
| | 21 | |
|
| | 22 | | public void OnPointerClick(PointerEventData eventData) |
| | 23 | | { |
| 0 | 24 | | Vector3 mousePosition = new Vector3(eventData.position.x, eventData.position.y, 0); // or Input.mousePositio |
| | 25 | |
|
| 0 | 26 | | if (TMP_TextUtilities.FindIntersectingLink(tmpTextBox, mousePosition, cameraToUse) != -1) |
| 0 | 27 | | HyperLinkClicked?.Invoke(); |
| 0 | 28 | | } |
| | 29 | | } |
| | 30 | | } |