2025-03-12 20:59:12 +08:00
|
|
|
using System;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
2025-11-20 15:40:38 +08:00
|
|
|
namespace AlicizaX.UI
|
2025-03-12 20:59:12 +08:00
|
|
|
{
|
|
|
|
|
public abstract class ViewHolder : MonoBehaviour
|
|
|
|
|
{
|
|
|
|
|
private RectTransform rectTransform;
|
2026-03-27 18:38:29 +08:00
|
|
|
|
|
|
|
|
internal event Action<ViewHolder> Destroyed;
|
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-05-30 13:43:08 +08:00
|
|
|
public string Name { get; internal set; }
|
2026-03-11 14:18:07 +08:00
|
|
|
|
2025-05-30 13:43:08 +08:00
|
|
|
public int Index { get; internal set; }
|
2025-03-12 20:59:12 +08:00
|
|
|
|
2026-03-31 15:18:50 +08:00
|
|
|
public int DataIndex { get; internal set; } = -1;
|
2026-03-27 18:38:29 +08:00
|
|
|
|
2026-03-31 15:18:50 +08:00
|
|
|
public RecyclerView RecyclerView { get; internal set; }
|
2025-05-30 13:43:08 +08:00
|
|
|
|
2026-03-31 15:18:50 +08:00
|
|
|
public uint BindingVersion { get; private set; }
|
2026-03-30 16:00:20 +08:00
|
|
|
|
2026-03-31 15:18:50 +08:00
|
|
|
public Vector2 SizeDelta => RectTransform.sizeDelta;
|
2025-03-12 20:59:12 +08:00
|
|
|
|
2026-03-31 15:18:50 +08:00
|
|
|
internal uint AdvanceBindingVersion()
|
2026-03-27 18:38:29 +08:00
|
|
|
{
|
2026-03-31 15:18:50 +08:00
|
|
|
BindingVersion = BindingVersion == uint.MaxValue ? 1u : BindingVersion + 1u;
|
|
|
|
|
return BindingVersion;
|
2026-03-27 18:38:29 +08:00
|
|
|
}
|
2026-03-27 14:38:26 +08:00
|
|
|
|
2026-03-31 15:18:50 +08:00
|
|
|
protected internal virtual void OnRecycled()
|
2025-03-28 13:34:33 +08:00
|
|
|
{
|
2026-03-31 15:18:50 +08:00
|
|
|
AdvanceBindingVersion();
|
|
|
|
|
Name = string.Empty;
|
|
|
|
|
Index = -1;
|
|
|
|
|
DataIndex = -1;
|
|
|
|
|
RecyclerView = null;
|
2025-03-28 13:34:33 +08:00
|
|
|
}
|
2025-04-01 15:21:02 +08:00
|
|
|
|
2026-03-27 18:38:29 +08:00
|
|
|
protected virtual void OnDestroy()
|
2025-04-02 14:53:08 +08:00
|
|
|
{
|
2026-03-27 18:38:29 +08:00
|
|
|
Destroyed?.Invoke(this);
|
|
|
|
|
Destroyed = null;
|
2025-04-02 14:53:08 +08:00
|
|
|
}
|
2025-03-12 20:59:12 +08:00
|
|
|
}
|
|
|
|
|
}
|