UIEventTrigger.cs 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. using System;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. [AddComponentMenu("NGUI/Interaction/Event Trigger")]
  5. public class UIEventTrigger : MonoBehaviour
  6. {
  7. private void OnHover(bool isOver)
  8. {
  9. if (UIEventTrigger.current != null)
  10. {
  11. return;
  12. }
  13. UIEventTrigger.current = this;
  14. if (isOver)
  15. {
  16. EventDelegate.Execute(this.onHoverOver);
  17. }
  18. else
  19. {
  20. EventDelegate.Execute(this.onHoverOut);
  21. }
  22. UIEventTrigger.current = null;
  23. }
  24. private void OnPress(bool pressed)
  25. {
  26. if (UIEventTrigger.current != null)
  27. {
  28. return;
  29. }
  30. UIEventTrigger.current = this;
  31. if (pressed)
  32. {
  33. EventDelegate.Execute(this.onPress);
  34. }
  35. else
  36. {
  37. EventDelegate.Execute(this.onRelease);
  38. }
  39. UIEventTrigger.current = null;
  40. }
  41. private void OnSelect(bool selected)
  42. {
  43. if (UIEventTrigger.current != null)
  44. {
  45. return;
  46. }
  47. UIEventTrigger.current = this;
  48. if (selected)
  49. {
  50. EventDelegate.Execute(this.onSelect);
  51. }
  52. else
  53. {
  54. EventDelegate.Execute(this.onDeselect);
  55. }
  56. UIEventTrigger.current = null;
  57. }
  58. private void OnClick()
  59. {
  60. if (UIEventTrigger.current != null)
  61. {
  62. return;
  63. }
  64. UIEventTrigger.current = this;
  65. EventDelegate.Execute(this.onClick);
  66. UIEventTrigger.current = null;
  67. }
  68. private void OnDoubleClick()
  69. {
  70. if (UIEventTrigger.current != null)
  71. {
  72. return;
  73. }
  74. UIEventTrigger.current = this;
  75. EventDelegate.Execute(this.onDoubleClick);
  76. UIEventTrigger.current = null;
  77. }
  78. private void OnDragStart()
  79. {
  80. if (UIEventTrigger.current != null)
  81. {
  82. return;
  83. }
  84. UIEventTrigger.current = this;
  85. EventDelegate.Execute(this.onDragStart);
  86. UIEventTrigger.current = null;
  87. }
  88. private void OnDragEnd()
  89. {
  90. if (UIEventTrigger.current != null)
  91. {
  92. return;
  93. }
  94. UIEventTrigger.current = this;
  95. EventDelegate.Execute(this.onDragEnd);
  96. UIEventTrigger.current = null;
  97. }
  98. private void OnDragOver(GameObject go)
  99. {
  100. if (UIEventTrigger.current != null)
  101. {
  102. return;
  103. }
  104. UIEventTrigger.current = this;
  105. EventDelegate.Execute(this.onDragOver);
  106. UIEventTrigger.current = null;
  107. }
  108. private void OnDragOut(GameObject go)
  109. {
  110. if (UIEventTrigger.current != null)
  111. {
  112. return;
  113. }
  114. UIEventTrigger.current = this;
  115. EventDelegate.Execute(this.onDragOut);
  116. UIEventTrigger.current = null;
  117. }
  118. private void OnDrag(Vector2 delta)
  119. {
  120. if (UIEventTrigger.current != null)
  121. {
  122. return;
  123. }
  124. UIEventTrigger.current = this;
  125. EventDelegate.Execute(this.onDrag);
  126. UIEventTrigger.current = null;
  127. }
  128. public static UIEventTrigger current;
  129. public List<EventDelegate> onHoverOver = new List<EventDelegate>();
  130. public List<EventDelegate> onHoverOut = new List<EventDelegate>();
  131. public List<EventDelegate> onPress = new List<EventDelegate>();
  132. public List<EventDelegate> onRelease = new List<EventDelegate>();
  133. public List<EventDelegate> onSelect = new List<EventDelegate>();
  134. public List<EventDelegate> onDeselect = new List<EventDelegate>();
  135. public List<EventDelegate> onClick = new List<EventDelegate>();
  136. public List<EventDelegate> onDoubleClick = new List<EventDelegate>();
  137. public List<EventDelegate> onDragStart = new List<EventDelegate>();
  138. public List<EventDelegate> onDragEnd = new List<EventDelegate>();
  139. public List<EventDelegate> onDragOver = new List<EventDelegate>();
  140. public List<EventDelegate> onDragOut = new List<EventDelegate>();
  141. public List<EventDelegate> onDrag = new List<EventDelegate>();
  142. }