EventsLogUtils.cs 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. using UnityEngine;
  2. using UnityEngine.UI;
  3. using UnityEngine.EventSystems;
  4. using Rokid.UXR.Interaction;
  5. namespace Rokid.UXR.Utility
  6. {
  7. public class EventsLogUtils : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler, IPointerDownHandler, IPointerUpHandler, IPointerClickHandler, IGesPointerEnter, IGesPointerExit
  8. {
  9. [SerializeField]
  10. private Text logText;
  11. [Tooltip("是否打印(UGUI)事件")]
  12. [SerializeField]
  13. private bool logPointerEvent = true;
  14. [Tooltip("是否打印自定义手势事件")]
  15. [SerializeField]
  16. private bool logCustomGesEvent = true;
  17. private int clickCount = 0;
  18. private int downCount = 0;
  19. private int upCount = 0;
  20. private int enterCount = 0;
  21. private int exitCount = 0;
  22. private int gesClickCount = 0;
  23. private TextMesh text;
  24. public void OnPointerEnter(PointerEventData eventData)
  25. {
  26. if (logPointerEvent)
  27. {
  28. if (logText != null)
  29. logText.text = $" OnPointerEnter, pointerEnter.Count: {++enterCount} {this.name}";
  30. RKLog.Info($"EventsLogUtils OnPointerEnter => {this.name}");
  31. }
  32. }
  33. public void OnPointerDown(PointerEventData eventData)
  34. {
  35. if (logPointerEvent)
  36. {
  37. if (logText != null)
  38. logText.text = $" OnPointerDown, pointerDown.Count: {++downCount} {this.name}";
  39. RKLog.Info($"EventsLogUtils OnPointerDown => {this.name}");
  40. }
  41. }
  42. public void OnPointerUp(PointerEventData eventData)
  43. {
  44. if (logPointerEvent)
  45. {
  46. if (logText != null)
  47. logText.text += $"\n OnPointerUp, pointerUp.Count: {++upCount} {this.name}";
  48. RKLog.Info($"EventsLogUtils OnPointerUp => {this.name}");
  49. }
  50. }
  51. public void OnPointerClick(PointerEventData eventData)
  52. {
  53. if (logPointerEvent)
  54. {
  55. if (logText != null)
  56. logText.text += $"\n OnPointerClick, pointerClick.Count: {++clickCount} {this.name}";
  57. RKLog.Info($"EventsLogUtils OnPointerClick => {this.name}");
  58. }
  59. }
  60. public void OnPointerExit(PointerEventData eventData)
  61. {
  62. if (logPointerEvent)
  63. {
  64. if (logText != null)
  65. logText.text += $"\n OnPointerExit, pointerExit.Count: {++exitCount} {this.name}";
  66. RKLog.Info($"EventsLogUtils OnPointerExit => {this.name}");
  67. }
  68. }
  69. public void OnGesPointerEnter()
  70. {
  71. if (logCustomGesEvent)
  72. {
  73. if (logText != null)
  74. logText.text = $" OnGesPointerClick, gesPointerClick.Count: {++gesClickCount} {this.name}";
  75. RKLog.Info($"EventsLogUtils OnGesPointerEnter => {this.name}");
  76. }
  77. }
  78. public void OnGesPointerExit()
  79. {
  80. if (logCustomGesEvent)
  81. {
  82. if (logText != null)
  83. logText.text += $" OnGesPointerClick, gesPointerClick.Count: {++gesClickCount} {this.name}";
  84. RKLog.Info($"EventsLogUtils OnGesPointerExit => {this.name}");
  85. }
  86. }
  87. }
  88. }