com.alicizax.unity.ui.exten.../Runtime/RecyclerView/ViewHolder/ViewHolder.cs
陈思海 dc8c840d69 RecyclerView 大优化
优化RecycleView 渲染架构
优化RecyclerView 渲染性能 增加 缓存 异步
增加Navagation导航锚点相关
2026-03-31 15:18:50 +08:00

59 lines
1.4 KiB
C#

using System;
using UnityEngine;
namespace AlicizaX.UI
{
public abstract class ViewHolder : MonoBehaviour
{
private RectTransform rectTransform;
internal event Action<ViewHolder> Destroyed;
public RectTransform RectTransform
{
get
{
if (rectTransform == null)
{
rectTransform = GetComponent<RectTransform>();
}
return rectTransform;
}
}
public string Name { get; internal set; }
public int Index { get; internal set; }
public int DataIndex { get; internal set; } = -1;
public RecyclerView RecyclerView { get; internal set; }
public uint BindingVersion { get; private set; }
public Vector2 SizeDelta => RectTransform.sizeDelta;
internal uint AdvanceBindingVersion()
{
BindingVersion = BindingVersion == uint.MaxValue ? 1u : BindingVersion + 1u;
return BindingVersion;
}
protected internal virtual void OnRecycled()
{
AdvanceBindingVersion();
Name = string.Empty;
Index = -1;
DataIndex = -1;
RecyclerView = null;
}
protected virtual void OnDestroy()
{
Destroyed?.Invoke(this);
Destroyed = null;
}
}
}