Пример #1
0
        public void TestGrowthStrategyExpandByAmount()
        {
            GameObject gameObject = new GameObject();

            Assert.IsNotNull(gameObject);
            gameObject.name = "PriorityObject";
            int            num            = 5;
            GrowPool       growPool       = ScriptableObject.CreateInstance <GrowPool>();
            ExpandByAmount expandByAmount = ScriptableObject.CreateInstance <ExpandByAmount>();

            expandByAmount.Amount         = num;
            growPool.GrowthStrategy       = expandByAmount;
            m_objectPool.PrefabToInstance = Object.Instantiate(gameObject);
            Assert.IsNotNull(m_objectPool.PrefabToInstance);
            m_objectPool.FullStrategy = growPool;
            m_objectPool.OnEnable();
            List <GameObject> list = new List <GameObject>();

            for (int i = 0; i < InitialPoolSize; i++)
            {
                GameObject gameObject2 = m_objectPool.Spawn();
                Assert.NotNull(gameObject2);
                list.Add(gameObject2);
            }
            GameObject gameObject3 = m_objectPool.Spawn();

            Assert.NotNull(gameObject3);
            Assert.AreEqual(false, list.Contains(gameObject3));
            Assert.AreEqual(InitialPoolSize + num, m_objectPool.Capacity);
            Object.DestroyImmediate(m_objectPool.PrefabToInstance);
            Object.DestroyImmediate(gameObject);
        }
Пример #2
0
        public void TestGrowPoolStrategyExpandByAmount()
        {
            int            num            = 5;
            GrowPool       growPool       = ScriptableObject.CreateInstance <GrowPool>();
            ExpandByAmount expandByAmount = ScriptableObject.CreateInstance <ExpandByAmount>();

            expandByAmount.Amount     = num;
            growPool.GrowthStrategy   = expandByAmount;
            m_objectPool.FullStrategy = growPool;
            List <PoolableObject> list = new List <PoolableObject>();

            for (int i = 0; i < InitialPoolSize; i++)
            {
                PoolableObject poolableObject = m_objectPool.Spawn();
                Assert.NotNull(poolableObject);
                list.Add(poolableObject);
            }
            PoolableObject poolableObject2 = m_objectPool.Spawn();

            Assert.NotNull(poolableObject2);
            Assert.AreEqual(false, list.Contains(poolableObject2));
            Assert.AreEqual(InitialPoolSize + num, m_objectPool.Capacity);
        }