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

@@ -11,6 +11,7 @@ namespace Darkmatter.App
{
[SerializeField] private PlatformPool platformPool;
[SerializeField] private LeaderBoardDataPool leaderBoardDataPool;
[SerializeField] private PlayerSplashPool playerSplashPool;
[SerializeField] private PlatformManager manager;
[SerializeField] private InputReaderSO inputReader;
[SerializeField] private GameSessionSO gameSession;
@@ -27,6 +28,7 @@ namespace Darkmatter.App
{
builder.RegisterComponent(platformPool).As<IPool<Platform>>();
builder.RegisterComponent(leaderBoardDataPool).As<IPool<LeaderBoardData>>();
builder.RegisterComponent(playerSplashPool).As<IPool<Splash>>();
builder.RegisterComponent(manager).As<IPlatformManager>();
builder.RegisterInstance(inputReader).As<IInputReader>();
builder.Register<ScoreService>(Lifetime.Singleton).As<IScoreService>();

View File

@@ -1,10 +0,0 @@
using UnityEngine;
namespace Darkmatter.Core
{
public interface IPoolable
{
void OnSpawn();
void OnDespawn();
}
}

View File

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

View File

@@ -29,6 +29,7 @@ namespace Darkmatter.Domain
{
isDead = false;
playerMaterial.color = playerMaterialColors[Random.Range(0, playerMaterialColors.Length)];
}
private void OnCollisionEnter(Collision collision)

View File

@@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: 519b6dff3c0f4154b911953421501a5d
guid: 9d68e43472632a542bc60a79aa0250ae
folderAsset: yes
DefaultImporter:
externalObjects: {}

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

View File

@@ -129,8 +129,8 @@ Material:
- _XRMotionVectorsPass: 1
- _ZWrite: 1
m_Colors:
- _BaseColor: {r: 0.22148229, g: 0.13866144, b: 0.7169812, a: 0}
- _Color: {r: 0.22148225, g: 0.13866141, b: 0.7169812, a: 0}
- _BaseColor: {r: 0.735849, g: 0.09371662, b: 0.48520926, a: 0}
- _Color: {r: 0.735849, g: 0.093716584, b: 0.48520917, a: 0}
- _EmissionColor: {r: 0, g: 0, b: 0, a: 1}
- _SpecColor: {r: 0.19999996, g: 0.19999996, b: 0.19999996, a: 1}
m_BuildTextureStacks: []

View File

@@ -116,7 +116,7 @@ Material:
- _XRMotionVectorsPass: 1
- _ZWrite: 1
m_Colors:
- _BaseColor: {r: 0.8679245, g: 0.8474546, b: 0.8474546, a: 0}
- _BaseColor: {r: 0.17342028, g: 0.754717, b: 0.0747597, a: 0}
- _Color: {r: 0.17342025, g: 0.75471693, b: 0.07475967, a: 0}
- _EmissionColor: {r: 0, g: 0, b: 0, a: 1}
- _SpecColor: {r: 0.19999996, g: 0.19999996, b: 0.19999996, a: 1}

View File

@@ -116,8 +116,8 @@ Material:
- _XRMotionVectorsPass: 1
- _ZWrite: 1
m_Colors:
- _BaseColor: {r: 0.7924528, g: 0.7552929, b: 0.063545756, a: 1}
- _Color: {r: 0.8113207, g: 0.53379685, b: 0.042096816, a: 1}
- _BaseColor: {r: 0.122641504, g: 0.12090601, b: 0.12090601, a: 0}
- _Color: {r: 0.12264148, g: 0.12090597, b: 0.12090597, a: 0}
- _EmissionColor: {r: 0, g: 0, b: 0, a: 1}
- _SpecColor: {r: 0.19999996, g: 0.19999996, b: 0.19999996, a: 1}
m_BuildTextureStacks: []

View File

@@ -146,7 +146,7 @@ GameObject:
serializedVersion: 6
m_Component:
- component: {fileID: 6295715214915275273}
- component: {fileID: 6369205413707127148}
- component: {fileID: 1566650972078747329}
m_Layer: 5
m_Name: Data
m_TagString: Untagged
@@ -177,7 +177,7 @@ RectTransform:
m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 817.4707, y: 120}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!114 &6369205413707127148
--- !u!114 &1566650972078747329
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
@@ -186,10 +186,10 @@ MonoBehaviour:
m_GameObject: {fileID: 340109946359880583}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 19899d49b8ee4db41a4ca8dd590ad4a1, type: 3}
m_Script: {fileID: 11500000, guid: eca7710de6fa5b94fa7c532a021816e7, type: 3}
m_Name:
m_EditorClassIdentifier: PresentationAssembly::Darkmatter.Presentation.LeaderboardData
posNumber: {fileID: 8966731343238371749}
m_EditorClassIdentifier: PresentationAssembly::Darkmatter.Presentation.LeaderBoardData
playerPos: {fileID: 8966731343238371749}
playerName: {fileID: 7140963729975583955}
playerScore: {fileID: 7199945981426735824}
--- !u!1 &4797370510838053142

View File

@@ -10,6 +10,7 @@ GameObject:
m_Component:
- component: {fileID: 4060169500839605980}
- component: {fileID: 8834857514908603474}
- component: {fileID: 7697948330971322712}
m_Layer: 0
m_Name: Splash
m_TagString: Untagged
@@ -91,3 +92,15 @@ SpriteRenderer:
m_SpriteTileMode: 0
m_WasSpriteAssigned: 1
m_SpriteSortPoint: 0
--- !u!114 &7697948330971322712
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 9000420296853654146}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 3db6a3cf6d18bec4f88fe6a46e141d5f, type: 3}
m_Name:
m_EditorClassIdentifier: PresentationAssembly::Darkmatter.Presentation.Splash

View File

@@ -300,7 +300,7 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: c15c9d815e963334384a40fbc8e84f23, type: 3}
m_Name:
m_EditorClassIdentifier: PresentationAssembly::Darkmatter.Presentation.LeaderBoardDataPool
prefab: {fileID: 6369205413707127148, guid: b16e394676a0f3e4dbf81cd523bf2325, type: 3}
prefab: {fileID: 1566650972078747329, guid: b16e394676a0f3e4dbf81cd523bf2325, type: 3}
prefabParent: {fileID: 1836214634}
poolSize: 15
--- !u!1 &63427161
@@ -534,6 +534,53 @@ AudioSource:
m_PreInfinity: 2
m_PostInfinity: 2
m_RotationOrder: 4
--- !u!1 &136903764
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 136903765}
- component: {fileID: 136903766}
m_Layer: 0
m_Name: PlayerSplashPool
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &136903765
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 136903764}
serializedVersion: 2
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 1111723450}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &136903766
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 136903764}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 9d59f9cfcc85400449668d96f0e2d89c, type: 3}
m_Name:
m_EditorClassIdentifier: PresentationAssembly::Darkmatter.Presentation.PlayerSplashPool
prefab: {fileID: 7697948330971322712, guid: 28c1e4391077e5c4e98f5924dc346fd9, type: 3}
prefabParent: {fileID: 1850425825}
poolSize: 5
--- !u!1 &155034150
GameObject:
m_ObjectHideFlags: 0
@@ -10984,6 +11031,7 @@ MonoBehaviour:
autoInjectGameObjects: []
platformPool: {fileID: 1073116393}
leaderBoardDataPool: {fileID: 62404198}
playerSplashPool: {fileID: 136903766}
manager: {fileID: 1850425826}
inputReader: {fileID: 11400000, guid: dfe12148dc4d7ea46b49e490c1b1aad5, type: 2}
gameSession: {fileID: 11400000, guid: 166236fc288d5a343ba6dd8ab704e653, type: 2}
@@ -13296,6 +13344,7 @@ Transform:
m_Children:
- {fileID: 1073116392}
- {fileID: 62404197}
- {fileID: 136903765}
m_Father: {fileID: 0}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &1148039065