Example #1
0
 /// <summary>
 /// Returns the number of clones (active and disabled) for the given pooled item
 /// </summary>
 private static int GetCloneCount(PooledItem pooledItem, PoolyExtension poolyExtension = null)
 {
     if (!Initialized)
     {
         Debug.LogWarning("[Pooly] Not has not finished it's initialization yet.");
     }
     return(Initialized ? pooledItem.CloneCount : -1);
 }
Example #2
0
 /// <summary>
 /// Despawns all the clones of all the prefabs from the given Pooly Extension
 /// </summary>
 public static void DespawnAllClonesFromPoolExtension(PoolyExtension poolExtension)
 {
     if (Instance == null)
     {
         return;
     }           // Scene change in progress
     if (poolExtension == null)
     {
         return;
     }
     foreach (var pooledItem in poolExtension.Pool.Values)
     {
         DespawnAllClonesOfPrefab(Pool[pooledItem.prefab.name].prefab);
     }
 }
Example #3
0
 /// <summary>
 /// Despawns all the clones of all the prefabs from the given Pooly Extension in the given category
 /// </summary>
 public static void DespawnAllClonesInCategory(PoolyExtension poolExtension, string category)
 {
     if (Instance == null)
     {
         return;
     }           // Scene change in progress
     if (poolExtension == null)
     {
         return;
     }
     if (string.IsNullOrEmpty(category))
     {
         Debug.LogWarning("[Pooly] Cannot Despawn All Clones In Category because you provided an empty/null category name."); return;
     }
     foreach (var pooledItem in poolExtension.Pool.Values)
     {
         if (category.Equals(pooledItem.category))
         {
             DespawnAllClonesOfPrefab(Pool[pooledItem.prefab.name].prefab);
         }
     }
 }
Example #4
0
        /// <summary>
        /// Created a pooled item for the given item and all the clones that need to be preloaded, in the specified pattern.
        /// </summary>
        public IEnumerator CreateClones(Item item, Transform poolTransform, Transform categoryTransform, PoolyExtension poolyExtension)
        {
            runningCoroutines++;
            var pooledItem = new PooledItem(new List <Transform>())
            {
                category                     = item.category,
                prefab                       = item.prefab,
                preloadCloneCount            = item.preloadCloneCount,
                limitCloneCount              = item.limitCloneCount,
                cloneCountLimit              = item.cloneCountLimit,
                limitCloneCreationPerFrame   = item.limitCloneCreationPerFrame,
                clonesOnFirstFrame           = item.clonesOnFirstFrame,
                clonesPerFrame               = item.clonesPerFrame,
                delayCreatingClonesForFrames = item.delayCreatingClonesForFrames,
                allowInstantiateMore         = item.allowInstantiateMore,
                allowRecycleClones           = item.allowRecycleClones,
                debug             = item.debug,
                poolTransform     = poolTransform,
                categoryTransform = categoryTransform
            };

            Pooly.Pool.Add(item.prefab.name, pooledItem);
#if UNITY_EDITOR
            if (PoolySettings.enableStatistics)
            {
                //pooledItem.ownStats = PoolyStatistics.ActivateStatsForPrefab(item.prefab.name, item.category, item.prefab, item.preloadCloneCount, poolyExtension);
                pooledItem.ownStats = PoolyStatistics.GetStatisticsItem(poolyExtension, item.category, item.prefab.name, item.prefab, item.preloadCloneCount);
            }
#endif
            int cloneNumber = 1;
            auxCloneTransform = null;
            if (item.limitCloneCreationPerFrame)
            {
                if (item.clonesOnFirstFrame > 0)
                {
                    while (cloneNumber <= item.preloadCloneCount && cloneNumber <= item.clonesOnFirstFrame)
                    {
                        auxCloneTransform = CreateClone(item.prefab, cloneNumber, categoryTransform);
                        Pooly.Pool[item.prefab.name].DisabledClones.Add(auxCloneTransform);
                        cloneNumber++;
                    }
                }

                if (item.delayCreatingClonesForFrames > 0)
                {
                    int delayedFrames = 0;
                    while (delayedFrames <= item.delayCreatingClonesForFrames)
                    {
                        yield return(null); delayedFrames++;
                    }
                }
                while (cloneNumber <= item.preloadCloneCount)
                {
                    auxCloneTransform = CreateClone(item.prefab, cloneNumber, categoryTransform);
                    Pooly.Pool[item.prefab.name].DisabledClones.Add(auxCloneTransform);
                    if (cloneNumber % item.clonesPerFrame == 0)
                    {
                        yield return(null);
                    }
                    cloneNumber++;
                }
            }
            else
            {
                while (cloneNumber <= item.preloadCloneCount)
                {
                    auxCloneTransform = CreateClone(item.prefab, cloneNumber, categoryTransform);
                    Pooly.Pool[item.prefab.name].DisabledClones.Add(auxCloneTransform);
                    cloneNumber++;
                }
            }
            if (poolyExtension != null)
            {
                poolyExtension.Pool.Add(item.prefab.name, pooledItem);
            }
            runningCoroutines--;
        }