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

36 lines
774 B
C#
Raw Normal View History

2025-03-12 20:59:12 +08:00
using UnityEngine;
public class UnityGameObjectFactory : IObjectFactory<GameObject>
{
protected GameObject template;
protected Transform parent;
public UnityGameObjectFactory(GameObject template, Transform parent)
{
this.template = template;
this.parent = parent;
}
public virtual GameObject Create()
{
return Object.Instantiate(template, parent);
}
public virtual void Reset(GameObject obj)
{
obj.SetActive(false);
obj.transform.position = Vector3.zero;
obj.transform.rotation = Quaternion.identity;
}
public virtual void Destroy(GameObject obj)
{
Object.Destroy(obj);
}
public virtual bool Validate(GameObject obj)
{
return true;
}
}