2025-11-20 15:40:38 +08:00
|
|
|
namespace AlicizaX.UI
|
2025-03-12 20:59:12 +08:00
|
|
|
{
|
2026-04-29 14:44:30 +08:00
|
|
|
using Cysharp.Text;
|
|
|
|
|
|
2025-03-12 20:59:12 +08:00
|
|
|
public sealed class SimpleViewProvider : ViewProvider
|
|
|
|
|
{
|
2026-03-31 15:18:50 +08:00
|
|
|
private readonly ObjectPool<ViewHolder> objectPool;
|
|
|
|
|
|
2026-04-29 14:44:30 +08:00
|
|
|
public override string PoolStats
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
#if UNITY_EDITOR || DEVELOPMENT_BUILD
|
|
|
|
|
return ZString.Format("hits={0}, misses={1}, destroys={2}, active={3}, inactive={4}, peakActive={5}, capacity={6}",
|
|
|
|
|
objectPool.HitCount,
|
|
|
|
|
objectPool.MissCount,
|
|
|
|
|
objectPool.DestroyCount,
|
|
|
|
|
objectPool.ActiveCount,
|
|
|
|
|
objectPool.InactiveCount,
|
|
|
|
|
objectPool.PeakActive,
|
|
|
|
|
objectPool.MaxSize);
|
|
|
|
|
#else
|
|
|
|
|
return string.Empty;
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-03-12 20:59:12 +08:00
|
|
|
|
|
|
|
|
public SimpleViewProvider(RecyclerView recyclerView, ViewHolder[] templates) : base(recyclerView, templates)
|
|
|
|
|
{
|
2025-05-28 19:37:38 +08:00
|
|
|
UnityComponentFactory<ViewHolder> factory = new(GetTemplate(), recyclerView.Content);
|
2026-03-31 15:18:50 +08:00
|
|
|
objectPool = new ObjectPool<ViewHolder>(factory, 0, 1);
|
2025-03-12 20:59:12 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override ViewHolder GetTemplate(string viewName = "")
|
|
|
|
|
{
|
2026-04-29 14:44:30 +08:00
|
|
|
return templates != null && templates.Length > 0 ? templates[0] : null;
|
2025-03-12 20:59:12 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override ViewHolder Allocate(string viewName)
|
|
|
|
|
{
|
2025-05-28 19:37:38 +08:00
|
|
|
var viewHolder = objectPool.Allocate();
|
|
|
|
|
viewHolder.gameObject.SetActive(true);
|
|
|
|
|
return viewHolder;
|
2025-03-12 20:59:12 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void Free(string viewName, ViewHolder viewHolder)
|
|
|
|
|
{
|
2025-05-28 19:37:38 +08:00
|
|
|
objectPool.Free(viewHolder);
|
2025-03-12 20:59:12 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void Reset()
|
|
|
|
|
{
|
|
|
|
|
Clear();
|
2026-03-27 18:38:29 +08:00
|
|
|
(Adapter as IItemRenderCacheOwner)?.ReleaseAllItemRenders();
|
2026-04-29 14:44:30 +08:00
|
|
|
objectPool.ClearInactive();
|
2025-03-12 20:59:12 +08:00
|
|
|
}
|
2026-03-31 15:18:50 +08:00
|
|
|
|
|
|
|
|
public override void PreparePool()
|
|
|
|
|
{
|
|
|
|
|
int warmCount = GetRecommendedWarmCount();
|
|
|
|
|
if (warmCount <= 0)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-29 14:44:30 +08:00
|
|
|
PrepareBucketPool(warmCount);
|
|
|
|
|
|
2026-03-31 15:18:50 +08:00
|
|
|
objectPool.EnsureCapacity(warmCount);
|
|
|
|
|
objectPool.Warm(warmCount);
|
|
|
|
|
}
|
2025-03-12 20:59:12 +08:00
|
|
|
}
|
|
|
|
|
}
|