Пример #1
0
        /// <summary>
        /// Method to create a new pool during run time. autoAddMissingPrefabPool must be enabled
        /// </summary>
        private static void CreateMissingPrefabPool(Transform missingTrans, string name)
        {
            var newPrefabPool = new EZ_PrefabPool();

            //Set the new pool options here
            newPrefabPool.parentTransform = parentTransform;
            newPrefabPool.poolCanGrow     = true;

            Pools.Add(name, newPrefabPool);

            // for the Inspector only
            var newPrefabPoolOption = new EZ_PrefabPoolOption();

            newPrefabPoolOption.prefabTransform = missingTrans;
            newPrefabPoolOption.poolCanGrow     = true;
            EZ_PoolManager.Instance.prefabPoolOptions.Add(newPrefabPoolOption);

            if (EZ_PoolManager.Instance.showDebugLog)
            {
                Debug.Log("EZ_PoolManager created Pool Item for missing item : " + name);
            }
        }
Пример #2
0
        /// <summary>
        /// Initializes all the pools set up by user in the editor, and adds them to the Dictionary.
        /// </summary>
        void Awake()
        {
            instance = this;

            parentTransform = this.transform;

            Pools.Clear();
            itemsMarkedForDeletion.Clear();

            if (!usePoolManager)
            {
                return;
            }

            // loop through all the pre-allocated pools and initialize all the pool
            for (var i = 0; i < prefabPoolOptions.Count; ++i)
            {
                var item            = prefabPoolOptions[i];
                var prefabTransform = item.prefabTransform;
                var name            = prefabTransform.name;

                if (item.instancesToPreload <= 0 && !item.poolCanGrow)
                {
                    itemsMarkedForDeletion.Add(item);
                    continue; // no need to pre-allocate any game obj, nothing else to do
                }

                if (prefabTransform == null)
                {
                    Debug.LogWarning("Item at index " + (i + 1) + " in the Pool has no prefab !");
                    continue;
                }

                if (Pools.ContainsKey(name))
                {
                    Debug.LogWarning("Duplicates found in the Pool : " + name);
                }

                // pre-allocate the game objs
                var tmpList = new List <Transform>();

                for (var j = 0; j < item.instancesToPreload; ++j)
                {
                    var newTransform = GameObject.Instantiate(prefabTransform, Vector3.zero, prefabTransform.rotation) as Transform;
                    newTransform.name   = name;
                    newTransform.parent = parentTransform;
                    newTransform.gameObject.SetActive(false);

                    tmpList.Add(newTransform);
                }

                var newPrefabPool = new EZ_PrefabPool(tmpList);
                newPrefabPool.showDebugLog    = item.showDebugLog;
                newPrefabPool.poolCanGrow     = item.poolCanGrow;
                newPrefabPool.parentTransform = parentTransform;

                newPrefabPool.cullDespawned = item.cullDespawned;
                newPrefabPool.cullAbove     = item.cullAbove;
                newPrefabPool.cullDelay     = item.cullDelay;
                newPrefabPool.cullAmount    = item.cullAmount;

                newPrefabPool.enableHardLimit = item.enableHardLimit;
                newPrefabPool.hardLimit       = item.hardLimit;

                newPrefabPool.recycle = item.recycle;

                Pools.Add(name, newPrefabPool); //add the pool to the Dictionary
            }

            foreach (var item in itemsMarkedForDeletion)
            {
                prefabPoolOptions.Remove(item);
            }

            itemsMarkedForDeletion.Clear();
        }
Пример #3
0
        /// <summary>
        /// Initializes all the pools set up by user in the editor, and adds them to the Dictionary.
        /// </summary>
        void Awake()
        {
            instance = this;

            parentTransform = this.transform;

            Pools.Clear();
            itemsMarkedForDeletion.Clear();

            if (!usePoolManager)
                return;

            // loop through all the pre-allocated pools and initialize all the pool
            for (var i = 0; i < prefabPoolOptions.Count; ++i)
            {
                var item = prefabPoolOptions[i];
                var prefabTransform = item.prefabTransform;
                var name = prefabTransform.name;

                if (item.instancesToPreload <= 0 && !item.poolCanGrow)
                {
                    itemsMarkedForDeletion.Add(item);
                    continue; // no need to pre-allocate any game obj, nothing else to do
                }

                if (prefabTransform == null)
                {
                    Debug.LogWarning("Item at index " + (i + 1) + " in the Pool has no prefab !");
                    continue;
                }

                if (Pools.ContainsKey(name))
                {
                    Debug.LogWarning("Duplicates found in the Pool : " + name);
                }

                // pre-allocate the game objs
                var tmpList = new List<Transform>();

                for (var j = 0; j < item.instancesToPreload; ++j)
                {
                    var newTransform = GameObject.Instantiate(prefabTransform, Vector3.zero, prefabTransform.rotation) as Transform;
                    newTransform.name = name;
                    newTransform.parent = parentTransform;
                    newTransform.gameObject.SetActive(false);

                    tmpList.Add(newTransform);
                }

                var newPrefabPool = new EZ_PrefabPool(tmpList);
                newPrefabPool.showDebugLog = item.showDebugLog;
                newPrefabPool.poolCanGrow = item.poolCanGrow;
                newPrefabPool.parentTransform = parentTransform;

                newPrefabPool.cullDespawned = item.cullDespawned;
                newPrefabPool.cullAbove = item.cullAbove;
                newPrefabPool.cullDelay = item.cullDelay;
                newPrefabPool.cullAmount = item.cullAmount;

                newPrefabPool.enableHardLimit = item.enableHardLimit;
                newPrefabPool.hardLimit = item.hardLimit;

                newPrefabPool.recycle = item.recycle;

                Pools.Add(name, newPrefabPool); //add the pool to the Dictionary
            }

            foreach (var item in itemsMarkedForDeletion)
            {
                prefabPoolOptions.Remove(item);
            }

            itemsMarkedForDeletion.Clear();
        }
Пример #4
0
        /// <summary>
        /// Method to create a new pool during run time. autoAddMissingPrefabPool must be enabled
        /// </summary>
        private static void CreateMissingPrefabPool(Transform missingTrans, string name)
        {
            var newPrefabPool = new EZ_PrefabPool();

            //Set the new pool options here
            newPrefabPool.parentTransform = parentTransform;
            newPrefabPool.poolCanGrow = true;

            Pools.Add(name, newPrefabPool);

            // for the Inspector only
            var newPrefabPoolOption = new EZ_PrefabPoolOption();
            newPrefabPoolOption.prefabTransform = missingTrans;
            newPrefabPoolOption.poolCanGrow = true;
            EZ_PoolManager.Instance.prefabPoolOptions.Add(newPrefabPoolOption);

            if (EZ_PoolManager.Instance.showDebugLog)
            {
                Debug.Log("EZ_PoolManager created Pool Item for missing item : " + name);
            }
        }