78 lines
1.9 KiB
C#
78 lines
1.9 KiB
C#
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<ViewHolder> Destroyed;
|
|
|
|
public RectTransform RectTransform
|
|
{
|
|
get
|
|
{
|
|
if (rectTransform == null)
|
|
{
|
|
rectTransform = GetComponent<RectTransform>();
|
|
}
|
|
|
|
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 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;
|
|
}
|
|
}
|
|
}
|