using System.Collections.Generic; using UnityEngine; namespace OctoberStudio.Pool { public class PoolsManager : MonoBehaviour { [SerializeField] List preloadedPools; private Dictionary pools; private void Awake() { pools = new Dictionary(); for (int i = 0; i < preloadedPools.Count; i++) { var data = preloadedPools[i]; int hash = data.name.GetHashCode(); var pool = new PoolObject(data.name, data.prefab, data.size); pools[hash] = pool; } } public PoolObject GetPool(string name) { return GetPool(name.GetHashCode()); } public PoolObject GetPool(int hash) { if (pools.ContainsKey(hash)) { return pools[hash]; } return null; } public GameObject GetEntity(string name) { return GetEntity(name.GetHashCode()); } public GameObject GetEntity(int hash) { var pool = GetPool(hash); if (pool != null) return pool.GetEntity(); return null; } public T GetEntity(string name) where T : Component { return GetEntity(name.GetHashCode()); } public T GetEntity(int hash) where T : Component { var pool = GetPool(hash); if (pool != null) return pool.GetEntity(); return null; } [System.Serializable] private class PoolData { public string name; public GameObject prefab; public int size; } } }