Example #1
0
        public static Pool GetPool(PooledMonobehaviour prefab)
        {
            if (pools_dict.ContainsKey(prefab))
            {
                return(pools_dict[prefab]);
            }

            var pool = new GameObject("Pool-" + (prefab).name).AddComponent <Pool>();

            pool.prefab = prefab;
            pool.GrowPool();
            pools_dict.Add(prefab, pool);
            return(pool);
        }
Example #2
0
 private void Awake()
 {
     foreach (var prefab in prefabs)
     {
         if (prefab == null)
         {
             Debug.LogError("Null prefab during preparation");
         }
         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();
             }
         }
     }
 }
Example #3
0
        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();
        }
Example #4
0
 private void AddObjectToAvailable(PooledMonobehaviour pooledObject)
 {
     disabledObjects.Add(pooledObject);
     objects.Enqueue(pooledObject);
 }