generic pool made
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
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");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 19899d49b8ee4db41a4ca8dd590ad4a1
|
||||
@@ -4,13 +4,14 @@ using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using VContainer;
|
||||
|
||||
public class Platform : MonoBehaviour, IPlatform
|
||||
public class Platform : MonoBehaviour, IPlatform , IPoolable
|
||||
{
|
||||
[SerializeField] private List<GameObject> _platformPiece = new List<GameObject>();
|
||||
[SerializeField] private Material _safeMaterial;
|
||||
[SerializeField] private Material _deathMaterial;
|
||||
[SerializeField] private ParticleSystem _particleSystem;
|
||||
|
||||
//for selecting random color
|
||||
[SerializeField]private Color[] safeMaterialColors;
|
||||
[SerializeField] private Color[] deathMaterialColors;
|
||||
|
||||
@@ -75,7 +76,15 @@ public class Platform : MonoBehaviour, IPlatform
|
||||
}
|
||||
}
|
||||
|
||||
public void OnSpawn()
|
||||
{
|
||||
hasAchievedScore = false;
|
||||
}
|
||||
|
||||
public void OnDespawn()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using Darkmatter.Core;
|
||||
using Darkmatter.Domain;
|
||||
using UnityEngine;
|
||||
using VContainer;
|
||||
|
||||
@@ -11,6 +12,7 @@ public class PlatformManager : MonoBehaviour,IPlatformManager
|
||||
|
||||
[SerializeField] private float inputScale = 360f;
|
||||
float rotAmount = 0;
|
||||
public bool hasFirstPlatformBuilt = false;
|
||||
|
||||
|
||||
private void Start()
|
||||
@@ -47,6 +49,15 @@ public class PlatformManager : MonoBehaviour,IPlatformManager
|
||||
{
|
||||
foreach (Platform platform in pool.All)
|
||||
{
|
||||
if (!hasFirstPlatformBuilt)
|
||||
{
|
||||
platform.SetPlatformRule(new FirstPlatformRule());
|
||||
hasFirstPlatformBuilt=true;
|
||||
}
|
||||
else
|
||||
{
|
||||
platform.SetPlatformRule(new OtherPlatformRule());
|
||||
}
|
||||
platform.gameObject.SetActive(true);
|
||||
platform.transform.position = new Vector3(0, yPos, 0);
|
||||
yPos--;
|
||||
@@ -56,6 +67,8 @@ public class PlatformManager : MonoBehaviour,IPlatformManager
|
||||
public void BuildNewPlatform()
|
||||
{
|
||||
Platform platform = pool.GetFromPool();
|
||||
platform.SetPlatformRule(new OtherPlatformRule());
|
||||
platform.gameObject.SetActive(true);
|
||||
platform.transform.position = new Vector3(0, yPos, 0);
|
||||
yPos--;
|
||||
}
|
||||
|
||||
@@ -1,63 +0,0 @@
|
||||
using Darkmatter.Core;
|
||||
using Darkmatter.Domain;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using VContainer;
|
||||
|
||||
public class PlatformPool : MonoBehaviour, IPool<Platform>
|
||||
{
|
||||
[SerializeField] private Platform platformPrefab;
|
||||
[SerializeField] private Transform platformParent;
|
||||
[SerializeField] private int poolSize = 10;
|
||||
|
||||
private Queue<Platform> _queue = new Queue<Platform>();
|
||||
|
||||
public IReadOnlyCollection<Platform> All => _queue;
|
||||
|
||||
[Inject] IObjectResolver resolver;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
SetupPool();
|
||||
}
|
||||
|
||||
void SetupPool()
|
||||
{
|
||||
Platform instance = null;
|
||||
for(int i = 0; i < poolSize; i++)
|
||||
{
|
||||
instance = Instantiate(platformPrefab,platformParent);
|
||||
resolver.Inject(instance);
|
||||
if (i == 0) instance.SetPlatformRule(new FirstPlatform());
|
||||
else instance.SetPlatformRule(new OtherPlatform());
|
||||
instance.gameObject.SetActive(false);
|
||||
_queue.Enqueue(instance);
|
||||
}
|
||||
}
|
||||
|
||||
public Platform GetFromPool()
|
||||
{
|
||||
if(_queue.Count == 0)
|
||||
{
|
||||
Platform newObj = Instantiate(platformPrefab,platformParent);
|
||||
newObj.SetPlatformRule(new OtherPlatform());
|
||||
_queue.Enqueue(newObj);
|
||||
return newObj;
|
||||
}
|
||||
Platform pooledObj = _queue.Dequeue();
|
||||
pooledObj.SetPlatformRule(new OtherPlatform());
|
||||
pooledObj.gameObject.SetActive(true);
|
||||
return pooledObj;
|
||||
}
|
||||
|
||||
public void ReturnToPool(Platform obj)
|
||||
{
|
||||
obj.gameObject.SetActive(false);
|
||||
_queue.Enqueue(obj);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,2 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4977d8686efb09b40a678a0fb6037eee
|
||||
Reference in New Issue
Block a user