ItemWidgetBasic.cs 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. using System;
  2. using Fort23.Core;
  3. using Fort23.Mono;
  4. using OfficeOpenXml.FormulaParsing.Excel.Functions.Logical;
  5. using UnityEngine;
  6. using UnityEngine.EventSystems;
  7. public class ItemWidgetBasic : UIComponent, IScorllListWidget
  8. {
  9. public bool isUseDrag = false;
  10. public bool isAddLongPressBtn = true;
  11. public LongPressBtn longPressBtn;
  12. public LongPressDragBtn longPressDragBtn;
  13. public ButtonAnimation animation = null;
  14. protected RectTransform _rectTransform;
  15. public System.Action<ItemWidgetBasic> OnClick
  16. {
  17. get { return onClick; }
  18. set
  19. {
  20. onClick = value;
  21. if (onContinueClick != null || onClick != null)
  22. {
  23. if (animation != null)
  24. animation.isEnabled = true;
  25. }
  26. else
  27. {
  28. if (animation != null)
  29. animation.isEnabled = false;
  30. }
  31. }
  32. }
  33. private System.Action<ItemWidgetBasic> onClick;
  34. public System.Action<ItemWidgetBasic> OnContinueClick
  35. {
  36. get { return onContinueClick; }
  37. set
  38. {
  39. onContinueClick = value;
  40. if (onContinueClick != null || onClick != null)
  41. {
  42. if (animation != null)
  43. animation.isEnabled = true;
  44. }
  45. else
  46. {
  47. if (animation != null)
  48. animation.isEnabled = false;
  49. }
  50. }
  51. }
  52. /// <summary>
  53. /// 拖拽开始事件
  54. /// </summary>
  55. public Action<PointerEventData, ItemWidgetBasic> onDragStart;
  56. /// <summary>
  57. /// 拖拽进行中事件
  58. /// </summary>
  59. public Action<PointerEventData, ItemWidgetBasic> onDrag;
  60. /// <summary>
  61. /// 拖拽结束事件
  62. /// </summary>
  63. public Action<PointerEventData, ItemWidgetBasic> onDragEnd;
  64. public Action<ItemWidgetBasic> onPointerEnter;
  65. public Action<ItemWidgetBasic> onPointerExit;
  66. private System.Action<ItemWidgetBasic> onContinueClick;
  67. public override void AddButtonEvent()
  68. {
  69. base.AddButtonEvent();
  70. }
  71. private void OnPointerExit(PointerEventData obj)
  72. {
  73. onPointerExit?.Invoke(this);
  74. }
  75. private void OnPointerEnter(PointerEventData obj)
  76. {
  77. onPointerEnter?.Invoke(this);
  78. }
  79. private void OnDragStart(PointerEventData obj)
  80. {
  81. onDragStart?.Invoke(obj, this);
  82. }
  83. private void OnDrag(PointerEventData obj)
  84. {
  85. onDrag?.Invoke(obj, this);
  86. }
  87. private void OnDragEnd(PointerEventData obj)
  88. {
  89. onDragEnd?.Invoke(obj, this);
  90. }
  91. public override CTask<bool> AsyncInit(object[] uiData)
  92. {
  93. if (_rectTransform == null)
  94. {
  95. _rectTransform = GObjectPoolInterface.GetComponent<RectTransform>();
  96. }
  97. if (isAddLongPressBtn)
  98. {
  99. if (isUseDrag)
  100. {
  101. longPressDragBtn = own.GetComponent<LongPressDragBtn>();
  102. if (longPressDragBtn == null)
  103. longPressDragBtn = own.AddComponent<LongPressDragBtn>();
  104. longPressDragBtn.onClick = () => OnClick?.Invoke(this);
  105. longPressDragBtn.longPress = () => OnContinueClick?.Invoke(this);
  106. longPressDragBtn.onDragStart = OnDragStart;
  107. longPressDragBtn.onDrag = OnDrag;
  108. longPressDragBtn.onDragEnd = OnDragEnd;
  109. longPressDragBtn.onPointerEnter = OnPointerEnter;
  110. longPressDragBtn.onPointerExit = OnPointerExit;
  111. }
  112. else
  113. {
  114. longPressBtn = own.GetComponent<LongPressBtn>();
  115. if (longPressBtn == null)
  116. longPressBtn = own.AddComponent<LongPressBtn>();
  117. longPressBtn.onClick = () => OnClick?.Invoke(this);
  118. longPressBtn.longPress = () => OnContinueClick?.Invoke(this);
  119. }
  120. }
  121. if (own.transform.Find("Button") != null)
  122. {
  123. animation = own.transform.Find("Button").gameObject.GetComponent<ButtonAnimation>();
  124. if (animation == null)
  125. animation = own.transform.Find("Button").gameObject.AddComponent<ButtonAnimation>();
  126. animation.isEnabled = false;
  127. }
  128. return base.AsyncInit(uiData);
  129. }
  130. public void SetBtnAnimation(bool isEnable)
  131. {
  132. if (animation)
  133. animation.isEnabled = isEnable;
  134. }
  135. public RectTransform Transform
  136. {
  137. get { return _rectTransform; }
  138. }
  139. public int index { get; set; }
  140. public virtual Vector2 GetSize()
  141. {
  142. return _rectTransform.sizeDelta;
  143. }
  144. public override void DormancyObj()
  145. {
  146. transform.GetComponent<RectTransform>().anchorMax = Vector2.one * 0.5f;
  147. transform.GetComponent<RectTransform>().anchorMin = Vector2.one * 0.5f;
  148. OnContinueClick = null;
  149. OnClick = null;
  150. base.DormancyObj();
  151. }
  152. public void OnPointerClick()
  153. {
  154. OnClick?.Invoke(this);
  155. }
  156. public void OnPointerContinueClick()
  157. {
  158. OnContinueClick?.Invoke(this);
  159. }
  160. }