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

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 9d68e43472632a542bc60a79aa0250ae
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,13 @@
using Darkmatter.Core;
using TMPro;
using UnityEngine;
namespace Darkmatter.Presentation
{
public class LeaderBoardData : MonoBehaviour,ILeaderBoardData
{
public TextMeshProUGUI playerPos;
public TextMeshProUGUI playerName;
public TextMeshProUGUI playerScore;
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: eca7710de6fa5b94fa7c532a021816e7

View File

@@ -1,25 +0,0 @@
using Darkmatter.Core;
using TMPro;
using UnityEngine;
using VContainer;
namespace Darkmatter.Presentation
{
public class LeaderBoardData : MonoBehaviour,IPoolable, ILeaderBoardData
{
public TextMeshProUGUI posNumber;
public TextMeshProUGUI playerName;
public TextMeshProUGUI playerScore;
public void OnDespawn()
{
Debug.Log("LB data Despawnned");
}
public void OnSpawn()
{
Debug.Log("LB data spawnned");
}
}
}

View File

@@ -1,2 +0,0 @@
fileFormatVersion: 2
guid: 19899d49b8ee4db41a4ca8dd590ad4a1

View File

@@ -4,7 +4,7 @@ using System.Collections.Generic;
using UnityEngine;
using VContainer;
public class Platform : MonoBehaviour, IPlatform , IPoolable
public class Platform : MonoBehaviour, IPlatform
{
[SerializeField] private List<GameObject> _platformPiece = new List<GameObject>();
[SerializeField] private Material _safeMaterial;
@@ -75,16 +75,6 @@ public class Platform : MonoBehaviour, IPlatform , IPoolable
platformManager.BuildNewPlatform();
}
}
public void OnSpawn()
{
hasAchievedScore = false;
}
public void OnDespawn()
{
}
}

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);
}

View File

@@ -0,0 +1,6 @@
using UnityEngine;
namespace Darkmatter.Presentation
{
public class PlayerSplashPool : ObjectPool<Splash> { }
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 9d59f9cfcc85400449668d96f0e2d89c

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 3dcc2bb2471f63b478b2b3e9697c0351
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,18 @@
using Darkmatter.Core;
using UnityEngine;
namespace Darkmatter.Presentation
{
public class Splash : MonoBehaviour
{
public void OnDespawn()
{
Debug.Log("Despawned splash");
}
public void OnSpawn()
{
Debug.Log("Spawnned Splash");
}
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 3db6a3cf6d18bec4f88fe6a46e141d5f

View File

@@ -20,7 +20,7 @@ namespace Darkmatter.Presentation
public void UpdateData(int rank,string name, string score)
{
LeaderBoardData data = Instantiate(LBplayerData, LBDataContainer);
data.posNumber.text = rank.ToString();
data.playerPos.text = rank.ToString();
data.playerName.text = name;
data.playerScore.text = score;
}