private Pool <T> CreatePool()
        {
            var pooledObjects = new List <Poolable <T> >(size);

            GetPrewarmedObjects(pooledObjects);

            var helper = new PoolHelper <T>(pooledObjects);

            StateRestorer = StateRestorer ?? new DefaultStateRestorer <T>();
            var poolableFactory = PoolableFactory ?? new PoolableFactory <T>(Prefab, transform, StateRestorer);

            expander = new PoolExpander <T>(pooledObjects, expandAmount, instantiatedPerFrame, poolableFactory);
            var pool = new Pool <T>(pooledObjects, helper, expander, StateRestorer);

            poolableFactory.Pool = pool;

            foreach (var pooled in pooledObjects)
            {
                pooled.Pool = pool;
            }

            int toInstantiate = size - pooledObjects.Count;

            if (toInstantiate > 0)
            {
                expander.Expand(toInstantiate);
            }

            return(pool);
        }
Exemple #2
0
        public Pool(List <Poolable <T> > pooledObjects, PoolHelper <T> helper, PoolExpander <T> expander, IPoolableStateResotrer <T> stateResotrer)
        {
            Assert.IsNotNull(pooledObjects);
            Assert.IsNotNull(helper);
            Assert.IsNotNull(expander);

            this.pooledObjects = pooledObjects;
            this.helper        = helper;
            this.expander      = expander;
            this.stateResotrer = stateResotrer;
        }