示例#1
0
        /// <summary>
        /// Initialize pool controller and all pool components.
        /// </summary>
        private void Initialize()
        {
            if (Instance != null)
            {
                Debug.LogError("POOL: There can only be one PoolController, detected multiple instances.");
                return;
            }

            if (pools != null && poolTable != null)
            {
                // rehydrating, editor recompile during playback
                Instance = this;
                return;
            }

            pools     = new List <Pool>();
            poolTable = new Hashtable();
            var removals = new List <Pool>();

            pools.AddRange(GetComponentsInChildren <Pool>(true));

            for (int i = 0; i < pools.Count; i++)
            {
                if (pools[i].prefab == null)
                {
                    removals.Add(pools[i]);
                    continue;
                }

                pools[i].name = string.Format("pool-{0}", pools[i].prefab.name);
                poolTable.Add(pools[i].name, pools[i]);

                pools[i].Initialize();
            }

            for (int i = 0; i < removals.Count; i++)
            {
                pools.Remove(removals[i]);
            }

            removals.Clear();
            Instance = this;
        }
示例#2
0
 /// <summary>
 /// Unity3D OnDisable event.
 /// </summary>
 private void OnDisable()
 {
     Instance = null;
     DestroyAll();
 }