Esempio n. 1
0
        public void TestGrowthStrategyDoubleInSize()
        {
            GameObject gameObject = new GameObject();

            Assert.IsNotNull(gameObject);
            gameObject.name = "PriorityObject";
            GrowPool growPool = ScriptableObject.CreateInstance <GrowPool>();

            growPool.GrowthStrategy       = ScriptableObject.CreateInstance <DoubleInSize>();
            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 * 2, m_objectPool.Capacity);
            Object.DestroyImmediate(m_objectPool.PrefabToInstance);
            Object.DestroyImmediate(gameObject);
        }
Esempio n. 2
0
        public void TestGrowPoolStrategyDoubleInSize()
        {
            GrowPool growPool = ScriptableObject.CreateInstance <GrowPool>();

            growPool.GrowthStrategy   = ScriptableObject.CreateInstance <DoubleInSize>();
            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 * 2, m_objectPool.Capacity);
        }
Esempio n. 3
0
        protected void Initialize()
        {
            if (m_fullStrategy == null)
            {
                GrowPool growPool = ScriptableObject.CreateInstance <GrowPool>();
                growPool.GrowthStrategy = ScriptableObject.CreateInstance <ExpandByAmount>();
                m_fullStrategy          = growPool;
            }
            int capacity = Capacity;

            if (m_objectPool != null)
            {
                Capacity     = 0;
                m_objectPool = null;
            }
            if (m_objectPool == null)
            {
                m_objectPool = new ObjectPool <GameObject>(capacity, m_fullStrategy, OnAllocateObject, OnObjectAllocated, OnObjectDeallocated, OnObjectUnspawned, OnReplaceObject);
                Capacity     = capacity;
            }
            UpdatePoolName();
        }
Esempio n. 4
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);
        }