59 lines
1.4 KiB
C#
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;
|
|
}
|
|
}
|
|
}
|