TMP_LinkOpener.cs 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using TMPro;
  4. using UnityEngine;
  5. using UnityEngine.EventSystems;
  6. namespace AppUI.Util.Input
  7. {
  8. [RequireComponent(typeof(TMP_Text))]
  9. public class TMP_LinkOpener : MonoBehaviour, IPointerClickHandler
  10. {
  11. public TMP_Text text;
  12. public void OnPointerClick(PointerEventData eventData)
  13. {
  14. int linkIndex = TMP_TextUtilities.FindIntersectingLink(
  15. text,
  16. UnityEngine.Input.mousePosition,
  17. null);
  18. if (linkIndex != -1)
  19. {
  20. TMP_LinkInfo linkInfo = text.textInfo.linkInfo[linkIndex];
  21. string linkId = linkInfo.GetLinkID();
  22. Debug.Log("Clicked Link: " + linkId);
  23. GameObject o = Instantiate(Resources.Load<GameObject>("Prefabs/Views/AgreementView"));
  24. switch (linkId)
  25. {
  26. case "agreement":
  27. o.GetComponent<AgreementView>().EnterUserAgreement();
  28. break;
  29. case "privacy":
  30. o.GetComponent<AgreementView>().EnterPrivacyAgreement();
  31. break;
  32. }
  33. }
  34. }
  35. }
  36. }