com.alicizax.unity.ui.exten.../Runtime/RecyclerView/ViewHolder/ViewHolder.cs

51 lines
1.2 KiB
C#
Raw Normal View History

2025-03-12 20:59:12 +08:00
using System;
using UnityEngine;
using UnityEngine.UI;
namespace AlicizaX.UI.RecyclerView
{
public abstract class ViewHolder : MonoBehaviour
{
private RectTransform rectTransform;
2025-03-28 13:34:33 +08:00
2025-03-12 20:59:12 +08:00
public RectTransform RectTransform
{
get
{
if (rectTransform == null)
{
rectTransform = GetComponent<RectTransform>();
}
2025-03-28 13:34:33 +08:00
2025-03-12 20:59:12 +08:00
return rectTransform;
}
2025-03-28 13:34:33 +08:00
private set { rectTransform = value; }
2025-03-12 20:59:12 +08:00
}
public string Name { get; set; }
public int Index { get; set; }
public Vector2 SizeDelta => RectTransform.sizeDelta;
2025-03-28 13:34:33 +08:00
public virtual void OnStop()
2025-03-12 20:59:12 +08:00
{
}
public abstract void BindViewData<T>(T data);
public virtual void BindItemClick<T>(T data, Action<T> action)
{
if (TryGetComponent(out Button button))
{
button.onClick.RemoveAllListeners();
button.onClick.AddListener(() => action?.Invoke(data));
}
}
2025-03-28 13:34:33 +08:00
public virtual void BindChoiceState(bool state)
{
}
2025-04-01 15:21:02 +08:00
2025-03-12 20:59:12 +08:00
}
}