ItemWidgetBasic.cs 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. using Fort23.Core;
  2. using Fort23.Mono;
  3. using UnityEngine;
  4. public class ItemWidgetBasic : UIComponent, IScorllListWidget
  5. {
  6. protected RectTransform _rectTransform;
  7. public System.Action<ItemWidgetBasic> onClick;
  8. public System.Action<ItemWidgetBasic> onContinueClick;
  9. public override void AddButtonEvent()
  10. {
  11. LongPressBtn longPressBtn = own.GetComponent<LongPressBtn>();
  12. if(longPressBtn == null)
  13. longPressBtn = own.AddComponent<LongPressBtn>();
  14. longPressBtn.onClick =() => onClick?.Invoke(this);
  15. longPressBtn.longPress =() => onContinueClick?.Invoke(this);
  16. base.AddButtonEvent();
  17. }
  18. public override CTask<bool> AsyncInit(object[] uiData)
  19. {
  20. if (_rectTransform == null)
  21. {
  22. _rectTransform = GObjectPoolInterface.GetComponent<RectTransform>();
  23. }
  24. return base.AsyncInit(uiData);
  25. }
  26. public RectTransform Transform
  27. {
  28. get { return _rectTransform; }
  29. }
  30. public int index { get; set; }
  31. public virtual Vector2 GetSize()
  32. {
  33. return _rectTransform.sizeDelta;
  34. }
  35. public override void DormancyObj()
  36. {
  37. transform.GetComponent<RectTransform>().anchorMax = Vector2.one * 0.5f;
  38. transform.GetComponent<RectTransform>().anchorMin = Vector2.one * 0.5f;
  39. base.DormancyObj();
  40. }
  41. public void OnPointerClick()
  42. {
  43. onClick?.Invoke(this);
  44. }
  45. public void OnPointerContinueClick()
  46. {
  47. onContinueClick?.Invoke(this);
  48. }
  49. }