예제 #1
0
파일: Pool.cs 프로젝트: feranmii/fer-tools
        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);
        }
예제 #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();
             }
         }
     }
 }
예제 #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
파일: Pool.cs 프로젝트: feranmii/fer-tools
 private void AddObjectToAvailable(PooledMonobehaviour pooledObject)
 {
     disabledObjects.Add(pooledObject);
     objects.Enqueue(pooledObject);
 }