using System.Collections.Generic; using UnityEngine; public class PoolManager : MonoBehaviour { public enum InstanceType { Deformer = 0, Splash = 1, Ball = 2 } public static Dictionary Instances; public float maxCount = 16f; public bool recycle; private int recycleIndex; public InstanceType type; public GameObject prefab; private void Awake() { if (Instances == null) { Instances = new Dictionary(); } if (!Instances.ContainsKey(type)) { Instances.Add(type, this); } } private void Start() { for (int i = 0; (float)i < maxCount; i++) { GameObject obj = Object.Instantiate(prefab); obj.transform.parent = base.transform; obj.name = type.ToString() + "_" + i; obj.SetActive(value: false); } } public GameObject getNextAvailable() { foreach (Transform item in base.transform) { if (!item.gameObject.activeSelf) { return item.gameObject; } } if (recycle && base.transform.childCount > recycleIndex) { if ((float)recycleIndex >= maxCount - 1f) { recycleIndex = 0; } GameObject result = base.transform.GetChild(recycleIndex).gameObject; recycleIndex++; return result; } return null; } }