Beispiel #1
0
        public void Clear_DestroysAllObjects()
        {
            //  setup
            PPool.Clear(prefab);

            //  arrange
            List <GameObject> list = new List <GameObject>();
            int count = 9;

            //  act
            for (int i = 0; i < count; i++)
            {
                GameObject g = PPool.Get(prefab);
                if (g != null)
                {
                    list.Add(g);
                }
            }
            for (int i = 0; i < count; i++)
            {
                PPool.Put(list[0]);
            }
            PPool.Clear(prefab);
            int total = PPool.GetAvailable(prefab) + PPool.GetInUse(prefab);

            //  assert
            Assert.AreEqual(0, total, "Pool contains objects");
        }
Beispiel #2
0
        public void GetInUse_IndicatesUsedQuantity()
        {
            //  setup
            PPool.Clear(prefab);

            //  arrange
            int count = 3;

            GameObject[] gos = new GameObject[count];

            //  act
            for (int i = 0; i < count; i++)
            {
                gos[i] = PPool.Get(prefab);
            }
            int resultForUsed = PPool.GetInUse(prefab);

            for (int i = 0; i < count; i++)
            {
                PPool.Put(gos[i]);
            }
            int resultForReclaimed = PPool.GetInUse(prefab);

            //  assert
            Assert.AreEqual(count, resultForUsed, "Pool has wrong number of active objects");
            Assert.AreEqual(0, resultForReclaimed, "Pool has wrong number of active objects");
        }
Beispiel #3
0
        public void SetNoQuantityLimit_RemovesLimit()
        {
            //  setup
            PPool.Clear(prefab);

            //  arrange
            int count = 9;
            int limit = count - 1;
            List <GameObject> list = new List <GameObject>();

            //  act
            PPool.SetLimit(prefab, poolSize: limit);
            for (int i = 0; i < count; i++)
            {
                GameObject g = PPool.Get(prefab);
                if (g != null)
                {
                    list.Add(g);
                }
            }
            int createdWhileLimted = list.Count;
            int countWhileLimited  = PPool.GetInUse(prefab);

            PPool.SetLimit(prefab, poolSize: PPool.UNLIMITED);
            for (int i = 0; i < count; i++)
            {
                GameObject g = PPool.Get(prefab);
                if (g != null)
                {
                    list.Add(g);
                }
            }
            int createUnlimited = list.Count;
            int countUnlimited  = PPool.GetInUse(prefab);

            //  assert
            Assert.AreEqual(limit, createdWhileLimted, "Wrong number created while limited");
            Assert.AreEqual(limit, countWhileLimited, "Pool reports wrong amount created while limited");
            Assert.AreEqual(limit + count, createUnlimited, "Unlimited object creation count incorrect");
            Assert.AreEqual(limit + count, countUnlimited, "Pool reports wrong amount created while unlimited");
        }