Example #1
0
        /// <summary>
        /// Initializes the pool.
        /// </summary>
        public void Initialize(Transform inPoolRoot = null, Transform inSpawnRoot = null)
        {
            if (m_InnerPool != null)
            {
                throw new InvalidOperationException("Cannot load pool twice");
            }

            if (inPoolRoot == null)
            {
                inPoolRoot = m_DefaultPoolRoot;
            }
            if (inSpawnRoot == null)
            {
                inSpawnRoot = m_DefaultSpawnRoot;
            }

            if (!inPoolRoot)
            {
                throw new ArgumentNullException("inPoolRoot", "No pool root, and no default pool root");
            }

            m_InnerPool = new PrefabPool <T>(Name, m_InitialCapacity, m_Prefab, inPoolRoot, inSpawnRoot, m_ResetTransformOnAlloc, !AllowLooseTyping());
            m_InnerPool.Config.RegisterOnAlloc(OnAlloc);
            m_InnerPool.Config.RegisterOnFree(OnFree);

            if (m_PrewarmOnInitialize)
            {
                m_InnerPool.Prewarm(m_InitialPrewarm);
            }
        }
Example #2
0
        /// <summary>
        /// Unloads the pool.
        /// </summary>
        public void Destroy()
        {
            if (m_InnerPool != null)
            {
                Reset();

                m_InnerPool.Dispose();
                m_InnerPool = null;
            }
        }