예제 #1
0
        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);
        }
예제 #2
0
 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();
             }
         }
     }
 }
예제 #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();
        }
예제 #4
0
 private void AddObjectToAvailable(PooledMonobehaviour pooledObject)
 {
     disabledObjects.Add(pooledObject);
     objects.Enqueue(pooledObject);
 }