com.alicizax.unity.ui.exten.../Runtime/RecyclerView/ObjectPool/UnityComponentFactory.cs

39 lines
777 B
C#
Raw Normal View History

2025-12-26 14:22:46 +08:00
namespace AlicizaX.UI
2025-05-28 19:37:38 +08:00
{
using UnityEngine;
2025-12-26 14:22:46 +08:00
public class UnityComponentFactory<T> : IObjectFactory<T> where T : Component
2025-05-28 19:37:38 +08:00
{
private T template;
private Transform parent;
public UnityComponentFactory(T template, Transform parent)
{
this.template = template;
this.parent = parent;
}
public T Create()
{
T obj = Object.Instantiate(template, parent);
return obj;
}
public void Destroy(T obj)
{
Object.Destroy(obj.gameObject);
}
public void Reset(T obj)
{
obj.gameObject.SetActive(false);
}
public bool Validate(T obj)
{
return true;
}
}
}