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; }
|
|
|
|
|
2025-04-02 14:53:08 +08:00
|
|
|
public bool ChoiseState { private set; get; }
|
|
|
|
|
2025-03-12 20:59:12 +08:00
|
|
|
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-04-02 14:53:08 +08:00
|
|
|
protected internal void BindChoiceState(bool state)
|
2025-03-28 13:34:33 +08:00
|
|
|
{
|
2025-04-02 14:53:08 +08:00
|
|
|
if (ChoiseState != state)
|
|
|
|
{
|
|
|
|
ChoiseState = state;
|
|
|
|
OnBindChoiceState(state);
|
|
|
|
}
|
2025-03-28 13:34:33 +08:00
|
|
|
}
|
2025-04-01 15:21:02 +08:00
|
|
|
|
2025-04-02 14:53:08 +08:00
|
|
|
protected internal virtual void OnBindChoiceState(bool state)
|
|
|
|
{
|
|
|
|
}
|
2025-03-12 20:59:12 +08:00
|
|
|
}
|
|
|
|
}
|