public static Pool GetPool(PooledMonobehaviour prefab) { if (pools.ContainsKey(prefab)) { return(pools[prefab]); } var pool = new GameObject("Pool-" + (prefab as Component).name).AddComponent <Pool>(); pool.prefab = prefab; pool.GrowPool(); pools.Add(prefab, pool); return(pool); }
private void Awake() { foreach (var prefab in prefabs) { if (prefab == null) { Debug.LogError("Null prefab in PoolPreparer"); } else { PooledMonobehaviour poolablePrefab = prefab.GetComponent <PooledMonobehaviour>(); if (poolablePrefab == null) { Debug.LogError("Prefab does not contain an IPoolable and can't be pooled"); } else { Pool.GetPool(poolablePrefab).GrowPool(); } } } }
private void OnValidate() { List <GameObject> prefabsToRemove = new List <GameObject>(); foreach (var prefab in prefabs.Where(t => t != null)) { if (PrefabUtility.GetPrefabType(prefab) != PrefabType.Prefab) { Debug.LogError(string.Format("{0} is not a prefab. It has been removed.", prefab.gameObject.name)); prefabsToRemove.Add(prefab.gameObject); } PooledMonobehaviour poolablePrefab = prefab.GetComponent <PooledMonobehaviour>(); if (poolablePrefab == null) { Debug.LogError("Prefab does not contain an IPoolable and can't be pooled. It has been removed."); prefabsToRemove.Add(prefab.gameObject); } } prefabs = prefabs .Where(t => t != null && prefabsToRemove.Contains(t.gameObject) == false) .ToArray(); }
private void AddObjectToAvailable(PooledMonobehaviour pooledObject) { disabledObjects.Add(pooledObject); objects.Enqueue(pooledObject); }