Exemple #1
0
        public void Expire_ReducesObjectCount()
        {
            //  setup
            PPool.Clear(prefab);

            //  arrange
            float             shortStale = 0;
            int               count      = 7;
            List <GameObject> list       = new List <GameObject>();

            PPool.SetLimit(prefab, staleDuration: shortStale);
            for (int i = 0; i < count; i++)
            {
                list.Add(PPool.Get(prefab));
            }
            for (int i = 0; i < count; i++)
            {
                PPool.Put(list[i]);
            }
            list.Clear();

            //  act
            PPool.Expire(prefab, true);
            int available = PPool.GetAvailable(prefab);

            //  assert
            Assert.AreEqual(0, available, "Pool did not expire unused objects");
        }
Exemple #2
0
    private void Update()
    {
        if (createPrefab)
        {
            createPrefab = false;
            prefab       = GameObject.CreatePrimitive(PrimitiveType.Cube);
            prefab.name  = "prefab";
            PPool.SetLimit(prefab, staleDuration: 2);
        }

        if (getItems)
        {
            getItems = false;
            list     = new List <GameObject>();
            for (int i = 0; i < count; i++)
            {
                list.Add(PPool.Get(prefab));
            }
        }

        if (putItems)
        {
            putItems = false;
            for (int i = 0; i < count; i++)
            {
                PPool.Put(list[i]);
            }
            list.Clear();
        }

        if (expirePool)
        {
            expirePool = false;
            PPool.Expire(prefab);
        }

        if (prewarm)
        {
            prewarm = false;
            PPool.Prewarm(prefab, count, 4);
        }
    }
Exemple #3
0
        public void SetLimit_AssignsPersistenceLimit()
        {
            //  setup
            PPool.Clear(prefab);

            //  arrange
            float duration = 0;

            PPool.SetLimit(prefab, staleDuration: duration);

            //  act
            GameObject instance  = PPool.Get(prefab);
            bool       putResult = PPool.Put(instance);

            Delay(duration + 1);
            PPool.Expire(prefab);
            Delay(duration + 1);
            int available = PPool.GetAvailable(prefab);

            //  assert
            Assert.IsTrue(putResult, "Pool indicates item was destroyed");
            Assert.AreEqual(0, available, "Pool kept objects past expiration");
        }