DragUIInput.cs 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.EventSystems;
  5. public class DragUIInput: UIWindowBase, IBeginDragHandler, IDragHandler, IEndDragHandler,IPointerDownHandler,IPointerUpHandler
  6. {
  7. private string m_UIEventKey;
  8. public InputEventRegisterInfo<InputUIOnBeginDragEvent> m_begionDrag;
  9. public InputEventRegisterInfo<InputUIOnDragEvent> m_onDrag;
  10. public InputEventRegisterInfo<InputUIOnEndDragEvent> m_endDrag;
  11. public InputEventRegisterInfo<InputUIOnMouseEvent> inputUIOnMouseEventDown;
  12. public InputEventRegisterInfo<InputUIOnMouseEvent> inputUIOnMouseEventUp;
  13. public virtual void InitEvent(string UIEventKey)
  14. {
  15. m_UIEventKey = UIEventKey;
  16. m_begionDrag = InputUIEventProxy.GetOnBeginDragListener(m_UIEventKey, name, name, OnBeginDragEvent);
  17. m_onDrag = InputUIEventProxy.GetOnDragListener(m_UIEventKey, name, name, OnDragEvent);
  18. m_endDrag = InputUIEventProxy.GetOnEndDragListener(m_UIEventKey, name, name, OnEndDragEvent);
  19. inputUIOnMouseEventDown = InputUIEventProxy.GetOnMouseListener(m_UIEventKey, name, name, true, OnMouseDownEvent);
  20. inputUIOnMouseEventUp = InputUIEventProxy.GetOnMouseListener(m_UIEventKey, name, name, false, OnMouseUpEvent);
  21. }
  22. protected override void OnUIDestroy()
  23. {
  24. if (m_begionDrag != null)
  25. {
  26. m_begionDrag.RemoveListener();
  27. }
  28. if (m_begionDrag != null)
  29. {
  30. m_onDrag.RemoveListener();
  31. }
  32. if (m_begionDrag != null)
  33. {
  34. m_endDrag.RemoveListener();
  35. }
  36. base.OnUIDestroy();
  37. }
  38. public void OnBeginDrag(PointerEventData eventData)
  39. {
  40. InputUIEventProxy.DispatchBeginDragEvent(name, name, null, eventData);
  41. }
  42. public void OnDrag(PointerEventData eventData)
  43. {
  44. InputUIEventProxy.DispatchDragEvent(name, name, null, eventData);
  45. }
  46. public void OnEndDrag(PointerEventData eventData)
  47. {
  48. InputUIEventProxy.DispatchEndDragEvent(name, name, null, eventData);
  49. }
  50. public void OnPointerDown(PointerEventData eventData)
  51. {
  52. InputUIEventProxy.DispatchMouseEvent(name, name, true, null);
  53. }
  54. public void OnPointerUp(PointerEventData eventData)
  55. {
  56. InputUIEventProxy.DispatchMouseEvent(name, name, false, null);
  57. }
  58. public virtual void OnMouseDownEvent(InputUIOnMouseEvent inputEvent)
  59. {
  60. }
  61. public virtual void OnMouseUpEvent(InputUIOnMouseEvent inputEvent)
  62. {
  63. }
  64. public virtual void OnEndDragEvent(InputUIOnEndDragEvent inputEvent)
  65. {
  66. }
  67. public virtual void OnDragEvent(InputUIOnDragEvent inputEvent)
  68. {
  69. }
  70. public virtual void OnBeginDragEvent(InputUIOnBeginDragEvent inputEvent)
  71. {
  72. }
  73. }