Create All Needed Scripts
This commit is contained in:
@@ -2,22 +2,23 @@ using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using Services.Interfaces;
|
||||
using UnityEngine;
|
||||
using Views;
|
||||
|
||||
namespace Services {
|
||||
public class ObjectPoolService:IObjectPool<GameObject> {
|
||||
private readonly GameObject prefab;
|
||||
public class ObjectPoolService:IObjectPool<GemView> {
|
||||
private readonly GemView prefab;
|
||||
private readonly Transform parent;
|
||||
private readonly int size;
|
||||
|
||||
private readonly Stack<GameObject> pool = new Stack<GameObject>();
|
||||
private readonly Stack<GemView> pool = new Stack<GemView>();
|
||||
|
||||
public ObjectPoolService(GameObject prefab, Transform parent, int size = 5) {
|
||||
public ObjectPoolService(GemView prefab, Transform parent, int size = 5) {
|
||||
this.prefab = prefab;
|
||||
this.parent = parent;
|
||||
this.size = size;
|
||||
}
|
||||
|
||||
public GameObject Get() {
|
||||
public GemView Get() {
|
||||
return this.pool.Count == 0 ? Object.Instantiate(this.prefab, this.parent) : this.pool.Pop();
|
||||
}
|
||||
|
||||
@@ -27,7 +28,7 @@ namespace Services {
|
||||
}
|
||||
}
|
||||
|
||||
public void Release(GameObject gameObject) {
|
||||
public void Release(GemView gameObject) {
|
||||
this.pool.Push(gameObject);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user