started using generic pooling

This commit is contained in:
Mausham
2025-12-17 18:50:53 -08:00
parent 2a7759228f
commit df4017f6be
24 changed files with 135 additions and 68 deletions

View File

@@ -1,13 +1,12 @@
using Darkmatter.Core;
using System.Collections.Generic;
using System.Runtime.InteropServices.WindowsRuntime;
using UnityEngine;
using VContainer;
using VContainer.Unity;
namespace Darkmatter.Presentation
{
public class ObjectPool<T> : MonoBehaviour,IPool<T> where T : MonoBehaviour, IPoolable
public class ObjectPool<T> : MonoBehaviour,IPool<T> where T : Component
{
[SerializeField] T prefab;
[SerializeField] private Transform prefabParent;
@@ -29,7 +28,6 @@ namespace Darkmatter.Presentation
{
T obj = Instantiate(prefab, prefabParent);
resolver.InjectGameObject(obj.gameObject);
obj.OnSpawn();
obj.gameObject.SetActive(false);
pool.Enqueue(obj);
}
@@ -41,7 +39,6 @@ namespace Darkmatter.Presentation
{
T obj = Instantiate(prefab, prefabParent);
resolver.InjectGameObject(obj.gameObject);
obj.OnSpawn();
obj.gameObject.SetActive(true);
pool.Enqueue(obj);
return obj;
@@ -52,7 +49,6 @@ namespace Darkmatter.Presentation
public void ReturnToPool(T obj)
{
obj.OnDespawn();
obj.gameObject.SetActive(false);
pool.Enqueue(obj);
}