UIEventListener.cs 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. using System;
  2. using UnityEngine;
  3. [AddComponentMenu("NGUI/Internal/Event Listener")]
  4. public class UIEventListener : MonoBehaviour
  5. {
  6. private void OnSubmit()
  7. {
  8. if (this.onSubmit != null)
  9. {
  10. this.onSubmit(base.gameObject);
  11. }
  12. }
  13. private void OnClick()
  14. {
  15. if (this.onClick != null)
  16. {
  17. this.onClick(base.gameObject);
  18. }
  19. }
  20. private void OnDoubleClick()
  21. {
  22. if (this.onDoubleClick != null)
  23. {
  24. this.onDoubleClick(base.gameObject);
  25. }
  26. }
  27. private void OnHover(bool isOver)
  28. {
  29. if (this.onHover != null)
  30. {
  31. this.onHover(base.gameObject, isOver);
  32. }
  33. }
  34. private void OnPress(bool isPressed)
  35. {
  36. if (this.onPress != null)
  37. {
  38. this.onPress(base.gameObject, isPressed);
  39. }
  40. }
  41. private void OnSelect(bool selected)
  42. {
  43. if (this.onSelect != null)
  44. {
  45. this.onSelect(base.gameObject, selected);
  46. }
  47. }
  48. private void OnScroll(float delta)
  49. {
  50. if (this.onScroll != null)
  51. {
  52. this.onScroll(base.gameObject, delta);
  53. }
  54. }
  55. private void OnDragStart()
  56. {
  57. if (this.onDragStart != null)
  58. {
  59. this.onDragStart(base.gameObject);
  60. }
  61. }
  62. private void OnDrag(Vector2 delta)
  63. {
  64. if (this.onDrag != null)
  65. {
  66. this.onDrag(base.gameObject, delta);
  67. }
  68. }
  69. private void OnDragOver()
  70. {
  71. if (this.onDragOver != null)
  72. {
  73. this.onDragOver(base.gameObject);
  74. }
  75. }
  76. private void OnDragOut()
  77. {
  78. if (this.onDragOut != null)
  79. {
  80. this.onDragOut(base.gameObject);
  81. }
  82. }
  83. private void OnDragEnd()
  84. {
  85. if (this.onDragEnd != null)
  86. {
  87. this.onDragEnd(base.gameObject);
  88. }
  89. }
  90. private void OnDrop(GameObject go)
  91. {
  92. if (this.onDrop != null)
  93. {
  94. this.onDrop(base.gameObject, go);
  95. }
  96. }
  97. private void OnKey(KeyCode key)
  98. {
  99. if (this.onKey != null)
  100. {
  101. this.onKey(base.gameObject, key);
  102. }
  103. }
  104. private void OnTooltip(bool show)
  105. {
  106. if (this.onTooltip != null)
  107. {
  108. this.onTooltip(base.gameObject, show);
  109. }
  110. }
  111. public static UIEventListener Get(GameObject go)
  112. {
  113. UIEventListener uieventListener = go.GetComponent<UIEventListener>();
  114. if (uieventListener == null)
  115. {
  116. uieventListener = go.AddComponent<UIEventListener>();
  117. }
  118. return uieventListener;
  119. }
  120. public object parameter;
  121. public UIEventListener.VoidDelegate onSubmit;
  122. public UIEventListener.VoidDelegate onClick;
  123. public UIEventListener.VoidDelegate onDoubleClick;
  124. public UIEventListener.BoolDelegate onHover;
  125. public UIEventListener.BoolDelegate onPress;
  126. public UIEventListener.BoolDelegate onSelect;
  127. public UIEventListener.FloatDelegate onScroll;
  128. public UIEventListener.VoidDelegate onDragStart;
  129. public UIEventListener.VectorDelegate onDrag;
  130. public UIEventListener.VoidDelegate onDragOver;
  131. public UIEventListener.VoidDelegate onDragOut;
  132. public UIEventListener.VoidDelegate onDragEnd;
  133. public UIEventListener.ObjectDelegate onDrop;
  134. public UIEventListener.KeyCodeDelegate onKey;
  135. public UIEventListener.BoolDelegate onTooltip;
  136. public delegate void VoidDelegate(GameObject go);
  137. public delegate void BoolDelegate(GameObject go, bool state);
  138. public delegate void FloatDelegate(GameObject go, float delta);
  139. public delegate void VectorDelegate(GameObject go, Vector2 delta);
  140. public delegate void ObjectDelegate(GameObject go, GameObject obj);
  141. public delegate void KeyCodeDelegate(GameObject go, KeyCode key);
  142. }