Beispiel #1
0
    public static UICommandHandle <TUIObject> GetInstance(TUIObject pObject_OrNull)
    {
        if (pObject_OrNull != null && g_mapHandle.TryGetValue(pObject_OrNull, out UICommandHandle <TUIObject> pHandle))
        {
            return(pHandle);
        }


        if (g_pPool == null)
        {
            g_pPool = new SimplePool <UICommandHandle <TUIObject> >(iCount => new UICommandHandle <TUIObject>(iCount), null, 1);
        }

        pHandle = g_pPool.DoPop();
        if (pObject_OrNull != null)
        {
            if (g_mapHandle.ContainsKey(pObject_OrNull) == false)
            {
                g_mapHandle.Add(pObject_OrNull, pHandle);
            }

            pHandle.Set_UIObject(pObject_OrNull);
        }

        return(pHandle.DoReset());
    }
    public void ICollectionView_UpdateItem(int iItemCount)
    {
        if (_pPool == null)
        {
            return;
        }

        while (_listChildrenObject.Count < iItemCount)
        {
            GameObject pObjectCopy = _pPool.DoPop();
            pObjectCopy.SetActive(true);

            _listChildrenObject.Add(pObjectCopy);
        }

        while (_listChildrenObject.Count > iItemCount && _listChildrenObject.Count > 0)
        {
            int        iRemoveIndex  = _listChildrenObject.Count - 1;
            GameObject pObjectReturn = _listChildrenObject[iRemoveIndex];
            _listChildrenObject.RemoveAt(iRemoveIndex);

            _pPool.DoPush(pObjectReturn);
            pObjectReturn.SetActive(false);
        }

        if (OnUpdate_CollectionItem == null)
        {
            Debug.LogWarning(name + " OnUpdate_CollectionItem == null", this);
            return;
        }

        for (int i = 0; i < _listChildrenObject.Count; i++)
        {
            OnUpdate_CollectionItem.Invoke(_listChildrenObject[i], i);
        }
    }
Beispiel #3
0
        public void 심플풀_동작테스트()
        {
            int iMaxPoolCount = 10;


            // Init & PrePooling (초기화 및 미리 생성) 테스트
            SimplePool <TestObject> pPool = new SimplePool <TestObject>(
                OnCreateItem: iCount => new TestObject(iCount),
                OnDestroyItem: (pTestObject) => pTestObject.OnDestroy(),
                iPrePoolCount: iMaxPoolCount);


            Assert.AreEqual(pPool.iAllInstanceCount, iMaxPoolCount);
            Assert.AreEqual(pPool.iUsedInstanceCount, 0);
            Assert.AreEqual(pPool.iUnUsedInstanceCount, iMaxPoolCount);


            // Pop(사용 안하는 오브젝트 요청) 테스트
            System.Random     pRandom    = new System.Random();
            int               iRandomPop = pRandom.Next(5, iMaxPoolCount);
            List <TestObject> listUsed   = new List <TestObject>();

            for (int i = 0; i < iRandomPop; i++)
            {
                TestObject pTestObject = pPool.DoPop();
                Assert.AreEqual(pTestObject.eState, TestObject.EState.Init);

                pTestObject.Used();
                Assert.AreEqual(pTestObject.eState, TestObject.EState.Used);

                listUsed.Add(pTestObject);
            }
            Assert.AreEqual(pPool.iAllInstanceCount, iMaxPoolCount);
            Assert.AreEqual(pPool.iUsedInstanceCount, iRandomPop);
            Assert.AreEqual(pPool.iUnUsedInstanceCount, iMaxPoolCount - iRandomPop);


            // Push(리턴) 테스트
            for (int i = 0; i < listUsed.Count; i++)
            {
                TestObject pTestObject = listUsed[i];
                pTestObject.UnUsed();
                Assert.AreEqual(pTestObject.eState, TestObject.EState.Unused);

                pPool.DoPush(pTestObject);
            }
            listUsed.Clear();
            Assert.AreEqual(pPool.iAllInstanceCount, iMaxPoolCount);
            Assert.AreEqual(pPool.iUsedInstanceCount, 0);
            Assert.AreEqual(pPool.iUnUsedInstanceCount, iMaxPoolCount);


            // MaxOver Pop 테스트
            int iNewMaxPoolCount = iRandomPop + iMaxPoolCount;

            for (int i = 0; i < iNewMaxPoolCount; i++)
            {
                TestObject pTestObject = pPool.DoPop();
                pTestObject.Used();
                Assert.AreEqual(pTestObject.eState, TestObject.EState.Used);

                listUsed.Add(pTestObject);
            }
            Assert.AreEqual(pPool.iAllInstanceCount, iNewMaxPoolCount);
            Assert.AreEqual(pPool.iUsedInstanceCount, iNewMaxPoolCount);
            Assert.AreEqual(pPool.iUnUsedInstanceCount, 0);


            // PushAll 테스트
            pPool.DoPushAll();
            Assert.AreEqual(pPool.iAllInstanceCount, iNewMaxPoolCount);
            Assert.AreEqual(pPool.iUsedInstanceCount, 0);
            Assert.AreEqual(pPool.iUnUsedInstanceCount, iNewMaxPoolCount);


            // Destroy 테스트
            pPool.DoDestroyPool(true);
            for (int i = 0; i < listUsed.Count; i++)
            {
                Assert.AreEqual(listUsed[i].eState, TestObject.EState.Destroyed);
            }
            Assert.AreEqual(pPool.iAllInstanceCount, 0);
            Assert.AreEqual(pPool.iUsedInstanceCount, 0);
            Assert.AreEqual(pPool.iUnUsedInstanceCount, 0);
        }