Exemplo n.º 1
0
 public void DeleteCategory(StatisticsPoolCategory category)
 {
     if (categories == null || categories.Count == 0 || !categories.Contains(category))
     {
         return;
     }
     categories.Remove(category);
 }
Exemplo n.º 2
0
        public static StatisticsItem GetStatisticsItem(PoolyExtension originPool, string category, string prefabName, Transform prefab, int preloadedClones)
        {
            //See if this scene is in the pools list (by default we consider this the MainPool)
            string   targetSceneName = Pooly.mainPoolSceneName;
            PoolType targetPoolType  = PoolType.MainPool;

            if (originPool != null) //this is a pool extension
            {
                targetSceneName = originPool.gameObject.scene.name;
                targetPoolType  = PoolType.PoolExtension;
            }

            StatisticsPool         statisticsPool         = null;
            StatisticsPoolCategory statisticsPoolCategory = null;
            StatisticsItem         statisticsItem         = null;

            if (Instance.pools == null)                                                       //the pools list null
            {
                Instance.pools = new List <StatisticsPool>();                                 //initialize the pools list
            }
            if (Instance.pools.Count == 0)                                                    //the pools list empty
            {
                statisticsPool         = new StatisticsPool(targetSceneName, targetPoolType); //create a new StatisticsPool
                statisticsPoolCategory = new StatisticsPoolCategory(category);                //create a new category for the new StatisticsPool
                statisticsPool.categories.Add(statisticsPoolCategory);                        //add the new category to the new StatisticsPool
                statisticsItem = new StatisticsItem(prefabName, prefab);
                statisticsItem.data.Add(new StatisticsItemData(preloadedClones, 0));          //add initial item data
                statisticsPoolCategory.items.Add(statisticsItem);                             //add the StatisticsItem to the new category under the new StatisticsPool
                Instance.pools.Add(statisticsPool);                                           //add the newly created StatisticsPool to the pools list
                return(statisticsItem);                                                       //return the reference to the StatisticsItem in order to quickly update its data values
            }

            if (statisticsPool == null)                        // a new StatisticsPool was NOT created
            {
                for (int i = 0; i < Instance.pools.Count; i++) //look for the pool where this prefab should be in
                {
                    if (Instance.pools[i].sceneName == targetSceneName && Instance.pools[i].poolType == targetPoolType)
                    {
                        statisticsPool = Instance.pools[i];
                        break;
                    }
                }
            }

            if (statisticsPool == null)                                                       //the StatisticsPool we were looking for does not exist, it needs to be created
            {
                statisticsPool         = new StatisticsPool(targetSceneName, targetPoolType); //create a new StatisticsPool
                statisticsPoolCategory = new StatisticsPoolCategory(category);                //create a new category for the new StatisticsPool
                statisticsPool.categories.Add(statisticsPoolCategory);                        //add the new category to the new StatisticsPool
                statisticsItem = new StatisticsItem(prefabName, prefab);                      //create a new StatisticsItem
                if (statisticsItem.data.Count == MAXIMUM_NUMBER_OF_RECORDS)
                {
                    statisticsItem.data.RemoveAt(0);
                }
                statisticsItem.data.Add(new StatisticsItemData(preloadedClones, 0)); //add initial item data
                statisticsPoolCategory.items.Add(statisticsItem);                    //add the StatisticsItem to the new category under the new StatisticsPool
                Instance.pools.Add(statisticsPool);                                  //add the newly created StatisticsPool to the pools list
                return(statisticsItem);                                              //return the reference to the StatisticsItem in order to quickly update its data values
            }

            //if we got here then we found a StatisticsPool where this prefab should be in
            //start searching for the prefab category

            int categoryIndex = statisticsPool.HasCategory(category);

            if (categoryIndex != -1) //the category exists in this pool
            {
                statisticsItem = statisticsPool.categories[categoryIndex].GetStatisticsItem(prefabName, prefab);
                if (statisticsItem != null) //the StatisticsItem was found
                {
                    if (statisticsItem.data.Count == MAXIMUM_NUMBER_OF_RECORDS)
                    {
                        statisticsItem.data.RemoveAt(0);
                    }
                    statisticsItem.data.Add(new StatisticsItemData(preloadedClones, 0)); //add initial item data
                    return(statisticsItem);                                              //return the reference to the StatisticsItem in order to quickly update its data values
                }

                //the item does not exist in this category, we need to add it
                statisticsItem = new StatisticsItem(prefabName, prefab); //create a new StatisticsItem
                if (statisticsItem.data.Count == MAXIMUM_NUMBER_OF_RECORDS)
                {
                    statisticsItem.data.RemoveAt(0);
                }
                statisticsItem.data.Add(new StatisticsItemData(preloadedClones, 0)); //add initial item data
                statisticsPool.categories[categoryIndex].items.Add(statisticsItem);
                return(statisticsItem);                                              //return the reference to the StatisticsItem in order to quickly update its data values
            }

            //the category does not exist, we need to create it
            statisticsPoolCategory = new StatisticsPoolCategory(category); //create a new category for the new StatisticsPool
            statisticsPool.categories.Add(statisticsPoolCategory);         //add the new category to the new StatisticsPool
            statisticsItem = new StatisticsItem(prefabName, prefab);       //create a new StatisticsItem
            if (statisticsItem.data.Count == MAXIMUM_NUMBER_OF_RECORDS)
            {
                statisticsItem.data.RemoveAt(0);
            }
            statisticsItem.data.Add(new StatisticsItemData(preloadedClones, 0)); //add initial item data
            statisticsPoolCategory.items.Add(statisticsItem);                    //add the StatisticsItem to the new category under the new StatisticsPool
            return(statisticsItem);                                              //return the reference to the StatisticsItem in order to quickly update its data values
        }