using System; using UnityEngine; namespace AlicizaX.UI { public abstract class ViewHolder : MonoBehaviour { private RectTransform rectTransform; private Action clickAction; private Action pointerEnterAction; private Action pointerExitAction; internal event Action Destroyed; public RectTransform RectTransform { get { if (rectTransform == null) { rectTransform = GetComponent(); } return rectTransform; } private set => rectTransform = value; } public string Name { get; internal set; } public int Index { get; internal set; } public Vector2 SizeDelta => RectTransform.sizeDelta; protected internal virtual void OnStart() { } protected internal virtual void OnRecycled() { } internal void SetInteractionCallbacks( Action clickAction = null, Action pointerEnterAction = null, Action pointerExitAction = null) { this.clickAction = clickAction; this.pointerEnterAction = pointerEnterAction; this.pointerExitAction = pointerExitAction; } public void ClearInteractionCallbacks() { clickAction = null; pointerEnterAction = null; pointerExitAction = null; } protected void InvokeClickAction() { clickAction?.Invoke(); } protected void InvokePointerEnterAction() { pointerEnterAction?.Invoke(); } protected void InvokePointerExitAction() { pointerExitAction?.Invoke(); } protected virtual void OnDestroy() { Destroyed?.Invoke(this); Destroyed = null; } } }