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.

62 lines
2.2 KiB

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