ItemWidgetBasic.cs 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. using Fort23.Core;
  2. using Fort23.Mono;
  3. using UnityEngine;
  4. public class ItemWidgetBasic : UIComponent, IScorllListWidget
  5. {
  6. public LongPressBtn longPressBtn;
  7. public ButtonAnimation animation = null;
  8. protected RectTransform _rectTransform;
  9. public System.Action<ItemWidgetBasic> OnClick
  10. {
  11. get { return onClick; }
  12. set
  13. {
  14. onClick = value;
  15. if (onContinueClick != null || onClick != null)
  16. {
  17. if(animation != null)
  18. animation.isEnabled = true;
  19. }
  20. else
  21. {
  22. if(animation != null)
  23. animation.isEnabled = false;
  24. }
  25. }
  26. }
  27. private System.Action<ItemWidgetBasic> onClick;
  28. public System.Action<ItemWidgetBasic> OnContinueClick
  29. {
  30. get { return onContinueClick; }
  31. set
  32. {
  33. onContinueClick = value;
  34. if (onContinueClick != null || onClick != null)
  35. {
  36. if(animation != null)
  37. animation.isEnabled = true;
  38. }
  39. else
  40. {
  41. if(animation != null)
  42. animation.isEnabled = false;
  43. }
  44. }
  45. }
  46. private System.Action<ItemWidgetBasic> onContinueClick;
  47. public override void AddButtonEvent()
  48. {
  49. longPressBtn = own.GetComponent<LongPressBtn>();
  50. if (longPressBtn == null)
  51. longPressBtn = own.AddComponent<LongPressBtn>();
  52. longPressBtn.onClick = () => OnClick?.Invoke(this);
  53. longPressBtn.longPress = () => OnContinueClick?.Invoke(this);
  54. if (own.transform.Find("Button") != null)
  55. {
  56. animation = own.transform.Find("Button").gameObject.GetComponent<ButtonAnimation>();
  57. if (animation == null)
  58. animation = own.transform.Find("Button").gameObject.AddComponent<ButtonAnimation>();
  59. animation.isEnabled = false;
  60. }
  61. base.AddButtonEvent();
  62. }
  63. public override CTask<bool> AsyncInit(object[] uiData)
  64. {
  65. if (_rectTransform == null)
  66. {
  67. _rectTransform = GObjectPoolInterface.GetComponent<RectTransform>();
  68. }
  69. return base.AsyncInit(uiData);
  70. }
  71. public void SetBtnAnimation(bool isEnable)
  72. {
  73. if(animation)
  74. animation.isEnabled = isEnable;
  75. }
  76. public RectTransform Transform
  77. {
  78. get { return _rectTransform; }
  79. }
  80. public int index { get; set; }
  81. public virtual Vector2 GetSize()
  82. {
  83. return _rectTransform.sizeDelta;
  84. }
  85. public override void DormancyObj()
  86. {
  87. transform.GetComponent<RectTransform>().anchorMax = Vector2.one * 0.5f;
  88. transform.GetComponent<RectTransform>().anchorMin = Vector2.one * 0.5f;
  89. OnContinueClick = null;
  90. OnClick = null;
  91. base.DormancyObj();
  92. }
  93. public void OnPointerClick()
  94. {
  95. OnClick?.Invoke(this);
  96. }
  97. public void OnPointerContinueClick()
  98. {
  99. OnContinueClick?.Invoke(this);
  100. }
  101. }