Create All Needed Scripts

This commit is contained in:
2025-12-14 09:23:38 +08:00
parent 980b26dd5e
commit 6fe70bd113
53 changed files with 1988 additions and 195 deletions

View File

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