using System; using Fort23.Core; using Fort23.Mono; using OfficeOpenXml.FormulaParsing.Excel.Functions.Logical; using UnityEngine; using UnityEngine.EventSystems; public class ItemWidgetBasic : UIComponent, IScorllListWidget { public bool isAddLongPressBtn = true; public LongPressBtn longPressBtn; public ButtonAnimation animation = null; protected RectTransform _rectTransform; public System.Action OnClick { get { return onClick; } set { onClick = value; if (onContinueClick != null || onClick != null) { if (animation != null) animation.isEnabled = true; } else { if (animation != null) animation.isEnabled = false; } } } private System.Action onClick; public System.Action OnContinueClick { get { return onContinueClick; } set { onContinueClick = value; if (onContinueClick != null || onClick != null) { if (animation != null) animation.isEnabled = true; } else { if (animation != null) animation.isEnabled = false; } } } /// /// 拖拽开始事件 /// public Action onDragStart; /// /// 拖拽进行中事件 /// public Action onDrag; /// /// 拖拽结束事件 /// public Action onDragEnd; public Action onPointerEnter; public Action onPointerExit; private System.Action onContinueClick; public override void AddButtonEvent() { if (isAddLongPressBtn) { longPressBtn = own.GetComponent(); if (longPressBtn == null) longPressBtn = own.AddComponent(); longPressBtn.onClick = () => OnClick?.Invoke(this); longPressBtn.longPress = () => OnContinueClick?.Invoke(this); longPressBtn.onDragStart = OnDragStart; longPressBtn.onDrag = OnDrag; longPressBtn.onDragEnd = OnDragEnd; longPressBtn.onPointerEnter = OnPointerEnter; longPressBtn.onPointerExit = OnPointerExit; } if (own.transform.Find("Button") != null) { animation = own.transform.Find("Button").gameObject.GetComponent(); if (animation == null) animation = own.transform.Find("Button").gameObject.AddComponent(); animation.isEnabled = false; } base.AddButtonEvent(); } private void OnPointerExit(PointerEventData obj) { onPointerExit?.Invoke(this); } private void OnPointerEnter(PointerEventData obj) { onPointerEnter?.Invoke(this); } private void OnDragStart(PointerEventData obj) { onDragStart?.Invoke(obj, this); } private void OnDrag(PointerEventData obj) { onDrag?.Invoke(obj, this); } private void OnDragEnd(PointerEventData obj) { onDragEnd?.Invoke(obj, this); } public override CTask AsyncInit(object[] uiData) { if (_rectTransform == null) { _rectTransform = GObjectPoolInterface.GetComponent(); } return base.AsyncInit(uiData); } public void SetBtnAnimation(bool isEnable) { if (animation) animation.isEnabled = isEnable; } public RectTransform Transform { get { return _rectTransform; } } public int index { get; set; } public virtual Vector2 GetSize() { return _rectTransform.sizeDelta; } public override void DormancyObj() { transform.GetComponent().anchorMax = Vector2.one * 0.5f; transform.GetComponent().anchorMin = Vector2.one * 0.5f; OnContinueClick = null; OnClick = null; base.DormancyObj(); } public void OnPointerClick() { OnClick?.Invoke(this); } public void OnPointerContinueClick() { OnContinueClick?.Invoke(this); } }