started using generic pooling
This commit is contained in:
@@ -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>();
|
||||
|
||||
@@ -1,10 +0,0 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace Darkmatter.Core
|
||||
{
|
||||
public interface IPoolable
|
||||
{
|
||||
void OnSpawn();
|
||||
void OnDespawn();
|
||||
}
|
||||
}
|
||||
@@ -1,2 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: bae72f3bdf0337048826015fe234b8f3
|
||||
@@ -29,6 +29,7 @@ namespace Darkmatter.Domain
|
||||
{
|
||||
isDead = false;
|
||||
playerMaterial.color = playerMaterialColors[Random.Range(0, playerMaterialColors.Length)];
|
||||
|
||||
}
|
||||
|
||||
private void OnCollisionEnter(Collision collision)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 519b6dff3c0f4154b911953421501a5d
|
||||
guid: 9d68e43472632a542bc60a79aa0250ae
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: eca7710de6fa5b94fa7c532a021816e7
|
||||
@@ -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");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,2 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 19899d49b8ee4db41a4ca8dd590ad4a1
|
||||
@@ -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()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace Darkmatter.Presentation
|
||||
{
|
||||
public class PlayerSplashPool : ObjectPool<Splash> { }
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9d59f9cfcc85400449668d96f0e2d89c
|
||||
8
Assets/DarkMatter/Code/Presentation/Splash.meta
Normal file
8
Assets/DarkMatter/Code/Presentation/Splash.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3dcc2bb2471f63b478b2b3e9697c0351
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
18
Assets/DarkMatter/Code/Presentation/Splash/Splash.cs
Normal file
18
Assets/DarkMatter/Code/Presentation/Splash/Splash.cs
Normal 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");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3db6a3cf6d18bec4f88fe6a46e141d5f
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user