Пример #1
0
        void Start()
        {
            // We need to setup such an item manually or through the editor (PoolManager only works with standard PoolItem types).
            PoolGeneric <CustomPoolItem> pool = new PoolGeneric <CustomPoolItem>(Prefab, 2);
            var poolItem = pool.GetPoolItemFromPool();

            // no need here to gget the component reference as that is handled by the CustomPoolItem.
            Debug.Log("Got pooled item - LifecycleComponent has initial value of " + poolItem.LifecycleComponent.Value);
            poolItem.LifecycleComponent.Value = 10;
            Debug.Log("Perform in game action - setting component value to 10 and then returning to pool.");
            pool.ReturnToPool(poolItem);

            poolItem = pool.GetPoolItemFromPool();
            // no need here to reget the component reference that we had in the LifeCycleCallback example.
            Debug.Log("Got pooled item second time - LifecycleComponent has initial value of " + poolItem.LifecycleComponent.Value);
            pool.ReturnToPool(poolItem);

            pool.ClearPool();
        }
Пример #2
0
 ///
 ///  get a reference to the pool for speed.
 ///
 void Start()
 {
     _pool = new PoolGeneric <CustomPoolItem>(Prefab, 100);
 }