No Description
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.

EventInterfaces.cs 14KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398
  1. namespace UnityEngine.EventSystems
  2. {
  3. /// <summary>
  4. /// Base class that all EventSystem events inherit from.
  5. /// </summary>
  6. public interface IEventSystemHandler
  7. {
  8. }
  9. /// <summary>
  10. /// Interface to implement if you wish to receive OnPointerMove callbacks.
  11. /// </summary>
  12. /// <remarks>
  13. /// Criteria for this event is implementation dependent. For example see StandAloneInputModule.
  14. /// </remarks>
  15. public interface IPointerMoveHandler : IEventSystemHandler
  16. {
  17. /// <summary>
  18. /// Use this callback to detect pointer move events
  19. /// </summary>
  20. void OnPointerMove(PointerEventData eventData);
  21. }
  22. /// <summary>
  23. /// Interface to implement if you wish to receive OnPointerEnter callbacks.
  24. /// </summary>
  25. /// <remarks>
  26. /// Criteria for this event is implementation dependent. For example see StandAloneInputModule.
  27. /// </remarks>
  28. public interface IPointerEnterHandler : IEventSystemHandler
  29. {
  30. /// <summary>
  31. /// Use this callback to detect pointer enter events
  32. /// </summary>
  33. void OnPointerEnter(PointerEventData eventData);
  34. }
  35. /// <summary>
  36. /// Interface to implement if you wish to receive OnPointerExit callbacks.
  37. /// </summary>
  38. /// <remarks>
  39. /// Criteria for this event is implementation dependent. For example see StandAloneInputModule.
  40. /// </remarks>
  41. public interface IPointerExitHandler : IEventSystemHandler
  42. {
  43. /// <summary>
  44. /// Use this callback to detect pointer exit events
  45. /// </summary>
  46. void OnPointerExit(PointerEventData eventData);
  47. }
  48. /// <summary>
  49. /// Interface to implement if you wish to receive OnPointerDown callbacks.
  50. /// </summary>
  51. /// <remarks>
  52. /// Criteria for this event is implementation dependent. For example see StandAloneInputModule.
  53. /// </remarks>
  54. public interface IPointerDownHandler : IEventSystemHandler
  55. {
  56. /// <summary>
  57. /// Use this callback to detect pointer down events.
  58. /// </summary>
  59. void OnPointerDown(PointerEventData eventData);
  60. }
  61. /// <summary>
  62. /// Interface to implement if you wish to receive OnPointerUp callbacks.
  63. /// Note: In order to receive OnPointerUp callbacks, you must also implement the EventSystems.IPointerDownHandler|IPointerDownHandler interface
  64. /// </summary>
  65. /// <remarks>
  66. /// Criteria for this event is implementation dependent. For example see StandAloneInputModule.
  67. /// </remarks>
  68. public interface IPointerUpHandler : IEventSystemHandler
  69. {
  70. /// <summary>
  71. /// Use this callback to detect pointer up events.
  72. /// </summary>
  73. void OnPointerUp(PointerEventData eventData);
  74. }
  75. /// <summary>
  76. /// Interface to implement if you wish to receive OnPointerClick callbacks.
  77. /// </summary>
  78. /// <remarks>
  79. /// Criteria for this event is implementation dependent. For example see StandAloneInputModule.
  80. /// </remarks>
  81. /// <remarks>
  82. /// Use the IPointerClickHandler Interface to handle click input using OnPointerClick callbacks. Ensure an Event System exists in the Scene to allow click detection. For click detection on non-UI GameObjects, ensure a EventSystems.PhysicsRaycaster is attached to the Camera.
  83. /// </remarks>
  84. /// <example>
  85. /// <code>
  86. /// <![CDATA[
  87. /// using UnityEngine;
  88. /// using UnityEngine.EventSystems;
  89. ///
  90. /// public class Example : MonoBehaviour, IPointerClickHandler
  91. /// {
  92. /// //Detect if a click occurs
  93. /// public void OnPointerClick(PointerEventData pointerEventData)
  94. /// {
  95. /// //Output to console the clicked GameObject's name and the following message. You can replace this with your own actions for when clicking the GameObject.
  96. /// Debug.Log(name + " Game Object Clicked!");
  97. /// }
  98. /// }
  99. /// ]]>
  100. ///</code>
  101. /// </example>
  102. public interface IPointerClickHandler : IEventSystemHandler
  103. {
  104. /// <summary>
  105. /// Use this callback to detect clicks.
  106. /// </summary>
  107. void OnPointerClick(PointerEventData eventData);
  108. }
  109. /// <summary>
  110. /// Interface to implement if you wish to receive OnBeginDrag callbacks.
  111. /// Note: You need to implement IDragHandler in addition to IBeginDragHandler.
  112. /// </summary>
  113. /// <remarks>
  114. /// Criteria for this event is implementation dependent. For example see StandAloneInputModule.
  115. /// </remarks>
  116. public interface IBeginDragHandler : IEventSystemHandler
  117. {
  118. /// <summary>
  119. /// Called by a BaseInputModule before a drag is started.
  120. /// </summary>
  121. void OnBeginDrag(PointerEventData eventData);
  122. }
  123. /// <summary>
  124. /// Interface to implement if you wish to receive OnInitializePotentialDrag callbacks.
  125. /// </summary>
  126. /// <remarks>
  127. /// Criteria for this event is implementation dependent. For example see StandAloneInputModule.
  128. /// </remarks>
  129. public interface IInitializePotentialDragHandler : IEventSystemHandler
  130. {
  131. /// <summary>
  132. /// Called by a BaseInputModule when a drag has been found but before it is valid to begin the drag.
  133. /// </summary>
  134. void OnInitializePotentialDrag(PointerEventData eventData);
  135. }
  136. /// <summary>
  137. /// Interface to implement if you wish to receive OnDrag callbacks.
  138. /// </summary>
  139. /// <remarks>
  140. /// Criteria for this event is implementation dependent. For example see StandAloneInputModule.
  141. /// </remarks>
  142. /// <example>
  143. /// <code>
  144. /// <![CDATA[
  145. /// using UnityEngine;
  146. /// using UnityEngine.EventSystems;
  147. /// using UnityEngine.UI;
  148. ///
  149. /// [RequireComponent(typeof(Image))]
  150. /// public class DragMe : MonoBehaviour, IBeginDragHandler, IDragHandler, IEndDragHandler
  151. /// {
  152. /// public bool dragOnSurfaces = true;
  153. ///
  154. /// private GameObject m_DraggingIcon;
  155. /// private RectTransform m_DraggingPlane;
  156. ///
  157. /// public void OnBeginDrag(PointerEventData eventData)
  158. /// {
  159. /// var canvas = FindInParents<Canvas>(gameObject);
  160. /// if (canvas == null)
  161. /// return;
  162. ///
  163. /// // We have clicked something that can be dragged.
  164. /// // What we want to do is create an icon for this.
  165. /// m_DraggingIcon = new GameObject("icon");
  166. ///
  167. /// m_DraggingIcon.transform.SetParent(canvas.transform, false);
  168. /// m_DraggingIcon.transform.SetAsLastSibling();
  169. ///
  170. /// var image = m_DraggingIcon.AddComponent<Image>();
  171. ///
  172. /// image.sprite = GetComponent<Image>().sprite;
  173. /// image.SetNativeSize();
  174. ///
  175. /// if (dragOnSurfaces)
  176. /// m_DraggingPlane = transform as RectTransform;
  177. /// else
  178. /// m_DraggingPlane = canvas.transform as RectTransform;
  179. ///
  180. /// SetDraggedPosition(eventData);
  181. /// }
  182. ///
  183. /// public void OnDrag(PointerEventData data)
  184. /// {
  185. /// if (m_DraggingIcon != null)
  186. /// SetDraggedPosition(data);
  187. /// }
  188. ///
  189. /// private void SetDraggedPosition(PointerEventData data)
  190. /// {
  191. /// if (dragOnSurfaces && data.pointerEnter != null && data.pointerEnter.transform as RectTransform != null)
  192. /// m_DraggingPlane = data.pointerEnter.transform as RectTransform;
  193. ///
  194. /// var rt = m_DraggingIcon.GetComponent<RectTransform>();
  195. /// Vector3 globalMousePos;
  196. /// if (RectTransformUtility.ScreenPointToWorldPointInRectangle(m_DraggingPlane, data.position, data.pressEventCamera, out globalMousePos))
  197. /// {
  198. /// rt.position = globalMousePos;
  199. /// rt.rotation = m_DraggingPlane.rotation;
  200. /// }
  201. /// }
  202. ///
  203. /// public void OnEndDrag(PointerEventData eventData)
  204. /// {
  205. /// if (m_DraggingIcon != null)
  206. /// Destroy(m_DraggingIcon);
  207. /// }
  208. ///
  209. /// static public T FindInParents<T>(GameObject go) where T : Component
  210. /// {
  211. /// if (go == null) return null;
  212. /// var comp = go.GetComponent<T>();
  213. ///
  214. /// if (comp != null)
  215. /// return comp;
  216. ///
  217. /// Transform t = go.transform.parent;
  218. /// while (t != null && comp == null)
  219. /// {
  220. /// comp = t.gameObject.GetComponent<T>();
  221. /// t = t.parent;
  222. /// }
  223. /// return comp;
  224. /// }
  225. /// }
  226. /// ]]>
  227. ///</code>
  228. /// </example>
  229. public interface IDragHandler : IEventSystemHandler
  230. {
  231. /// <summary>
  232. /// When dragging is occurring this will be called every time the cursor is moved.
  233. /// </summary>
  234. void OnDrag(PointerEventData eventData);
  235. }
  236. /// <summary>
  237. /// Interface to implement if you wish to receive OnEndDrag callbacks.
  238. /// Note: You need to implement IDragHandler in addition to IEndDragHandler.
  239. /// </summary>
  240. /// <remarks>
  241. /// Criteria for this event is implementation dependent. For example see StandAloneInputModule.
  242. /// </remarks>
  243. public interface IEndDragHandler : IEventSystemHandler
  244. {
  245. /// <summary>
  246. /// Called by a BaseInputModule when a drag is ended.
  247. /// </summary>
  248. void OnEndDrag(PointerEventData eventData);
  249. }
  250. /// <summary>
  251. /// Interface to implement if you wish to receive OnDrop callbacks.
  252. /// </summary>
  253. /// <example>
  254. /// <code>
  255. /// <![CDATA[
  256. /// using UnityEngine;
  257. /// using UnityEngine.EventSystems;
  258. ///
  259. /// public class DropMe : MonoBehaviour, IDropHandler
  260. /// {
  261. /// public void OnDrop(PointerEventData data)
  262. /// {
  263. /// if (data.pointerDrag != null)
  264. /// {
  265. /// Debug.Log ("Dropped object was: " + data.pointerDrag);
  266. /// }
  267. /// }
  268. /// }
  269. /// ]]>
  270. ///</code>
  271. /// </example>
  272. /// <remarks>
  273. /// Criteria for this event is implementation dependent. For example see StandAloneInputModule.
  274. /// </remarks>
  275. public interface IDropHandler : IEventSystemHandler
  276. {
  277. /// <summary>
  278. /// Called by a BaseInputModule on a target that can accept a drop.
  279. /// </summary>
  280. void OnDrop(PointerEventData eventData);
  281. }
  282. /// <summary>
  283. /// Interface to implement if you wish to receive OnScroll callbacks.
  284. /// </summary>
  285. /// <remarks>
  286. /// Criteria for this event is implementation dependent. For example see StandAloneInputModule.
  287. /// </remarks>
  288. public interface IScrollHandler : IEventSystemHandler
  289. {
  290. /// <summary>
  291. /// Use this callback to detect scroll events.
  292. /// </summary>
  293. void OnScroll(PointerEventData eventData);
  294. }
  295. /// <summary>
  296. /// Interface to implement if you wish to receive OnUpdateSelected callbacks.
  297. /// </summary>
  298. /// <remarks>
  299. /// Criteria for this event is implementation dependent. For example see StandAloneInputModule.
  300. /// </remarks>
  301. public interface IUpdateSelectedHandler : IEventSystemHandler
  302. {
  303. /// <summary>
  304. /// Called by the EventSystem when the object associated with this EventTrigger is updated.
  305. /// </summary>
  306. /// <example>
  307. /// <code>
  308. /// <![CDATA[
  309. /// using UnityEngine;
  310. /// using UnityEngine.EventSystems;
  311. ///
  312. /// public class UpdateSelectedExample : MonoBehaviour, IUpdateSelectedHandler
  313. /// {
  314. /// public void OnUpdateSelected(BaseEventData data)
  315. /// {
  316. /// Debug.Log("OnUpdateSelected called.");
  317. /// }
  318. /// }
  319. /// ]]>
  320. ///</code>
  321. /// </example>
  322. void OnUpdateSelected(BaseEventData eventData);
  323. }
  324. /// <summary>
  325. /// Interface to implement if you wish to receive OnSelect callbacks.
  326. /// </summary>
  327. /// <remarks>
  328. /// Criteria for this event is implementation dependent. For example see StandAloneInputModule.
  329. /// </remarks>
  330. public interface ISelectHandler : IEventSystemHandler
  331. {
  332. void OnSelect(BaseEventData eventData);
  333. }
  334. /// <summary>
  335. /// Interface to implement if you wish to receive OnDeselect callbacks.
  336. /// </summary>
  337. /// <remarks>
  338. /// Criteria for this event is implementation dependent. For example see StandAloneInputModule.
  339. /// </remarks>
  340. public interface IDeselectHandler : IEventSystemHandler
  341. {
  342. /// <summary>
  343. /// Called by the EventSystem when a new object is being selected.
  344. /// </summary>
  345. void OnDeselect(BaseEventData eventData);
  346. }
  347. /// <summary>
  348. /// Interface to implement if you wish to receive OnMove callbacks.
  349. /// </summary>
  350. /// <remarks>
  351. /// Criteria for this event is implementation dependent. For example see StandAloneInputModule.
  352. /// </remarks>
  353. public interface IMoveHandler : IEventSystemHandler
  354. {
  355. /// <summary>
  356. /// Called by a BaseInputModule when a move event occurs.
  357. /// </summary>
  358. void OnMove(AxisEventData eventData);
  359. }
  360. /// <summary>
  361. /// Interface to implement if you wish to receive OnSubmit callbacks.
  362. /// </summary>
  363. /// <remarks>
  364. /// Criteria for this event is implementation dependent. For example see StandAloneInputModule.
  365. /// </remarks>
  366. public interface ISubmitHandler : IEventSystemHandler
  367. {
  368. void OnSubmit(BaseEventData eventData);
  369. }
  370. /// <summary>
  371. /// Interface to implement if you wish to receive OnCancel callbacks.
  372. /// </summary>
  373. /// <remarks>
  374. /// Criteria for this event is implementation dependent. For example see StandAloneInputModule.
  375. /// </remarks>
  376. public interface ICancelHandler : IEventSystemHandler
  377. {
  378. void OnCancel(BaseEventData eventData);
  379. }
  380. }