com.alicizax.unity.ui.exten.../Runtime/RecyclerView/ObjectPool/UnityMixedGameObjectFactory.cs
2025-05-28 19:37:38 +08:00

45 lines
1.2 KiB
C#

namespace SimpleObjectPool
{
using UnityEngine;
internal class UnityMixedGameObjectFactory : IMixedObjectFactory<GameObject>
{
protected GameObject template;
protected Transform parent;
public UnityMixedGameObjectFactory(GameObject template, Transform parent)
{
this.template = template;
this.parent = parent;
}
public GameObject Create(string typeName)
{
GameObject obj = Object.Instantiate(template, parent);
GameObject model = Object.Instantiate(Resources.Load<GameObject>("ObjectPools/" + typeName), obj.transform);
model.transform.position = Vector3.zero;
model.transform.rotation = Quaternion.identity;
return obj;
}
public void Destroy(string typeName, GameObject obj)
{
Object.Destroy(obj);
}
public void Reset(string typeName, GameObject obj)
{
obj.SetActive(false);
obj.transform.position = Vector3.zero;
obj.transform.rotation = Quaternion.identity;
}
public bool Validate(string typeName, GameObject obj)
{
return true;
}
}
}