Global Game Jam 2022
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

73 lines
2.6 KiB

  1. using UnityEngine;
  2. namespace TMPro.Examples
  3. {
  4. public class TMP_TextEventCheck : MonoBehaviour
  5. {
  6. public TMP_TextEventHandler TextEventHandler;
  7. private TMP_Text m_TextComponent;
  8. void OnEnable()
  9. {
  10. if (TextEventHandler != null)
  11. {
  12. // Get a reference to the text component
  13. m_TextComponent = TextEventHandler.GetComponent<TMP_Text>();
  14. TextEventHandler.onCharacterSelection.AddListener(OnCharacterSelection);
  15. TextEventHandler.onSpriteSelection.AddListener(OnSpriteSelection);
  16. TextEventHandler.onWordSelection.AddListener(OnWordSelection);
  17. TextEventHandler.onLineSelection.AddListener(OnLineSelection);
  18. TextEventHandler.onLinkSelection.AddListener(OnLinkSelection);
  19. }
  20. }
  21. void OnDisable()
  22. {
  23. if (TextEventHandler != null)
  24. {
  25. TextEventHandler.onCharacterSelection.RemoveListener(OnCharacterSelection);
  26. TextEventHandler.onSpriteSelection.RemoveListener(OnSpriteSelection);
  27. TextEventHandler.onWordSelection.RemoveListener(OnWordSelection);
  28. TextEventHandler.onLineSelection.RemoveListener(OnLineSelection);
  29. TextEventHandler.onLinkSelection.RemoveListener(OnLinkSelection);
  30. }
  31. }
  32. void OnCharacterSelection(char c, int index)
  33. {
  34. Debug.Log("Character [" + c + "] at Index: " + index + " has been selected.");
  35. }
  36. void OnSpriteSelection(char c, int index)
  37. {
  38. Debug.Log("Sprite [" + c + "] at Index: " + index + " has been selected.");
  39. }
  40. void OnWordSelection(string word, int firstCharacterIndex, int length)
  41. {
  42. Debug.Log("Word [" + word + "] with first character index of " + firstCharacterIndex + " and length of " + length + " has been selected.");
  43. }
  44. void OnLineSelection(string lineText, int firstCharacterIndex, int length)
  45. {
  46. Debug.Log("Line [" + lineText + "] with first character index of " + firstCharacterIndex + " and length of " + length + " has been selected.");
  47. }
  48. void OnLinkSelection(string linkID, string linkText, int linkIndex)
  49. {
  50. if (m_TextComponent != null)
  51. {
  52. TMP_LinkInfo linkInfo = m_TextComponent.textInfo.linkInfo[linkIndex];
  53. }
  54. Debug.Log("Link Index: " + linkIndex + " with ID [" + linkID + "] and Text \"" + linkText + "\" has been selected.");
  55. }
  56. }
  57. }