コード例 #1
0
ファイル: AssetsPooling.cs プロジェクト: firefishes/ShipDock
        public void ToPool(int poolName, GameObject target, OnGameObjectPoolItem onRevert = null, bool visible = false)
        {
            if (target == null || mIsDispose)
            {
                return;
            }
            else
            {
            }

            onRevert?.Invoke(target);

            if (mPool.IsContainsKey(poolName))
            {
                int elmMax = (mPoolElmMax.IsContainsKey(poolName)) ? mPoolElmMax[poolName] : int.MaxValue;
                Stack <GameObject> pool = mPool[poolName];
                if (pool.Count < elmMax)
                {
                    pool.Push(target);

                    if (PoolContainer != default)
                    {
                        PoolContainer.Collect(target, visible);
                    }
                    else
                    {
                        target.SetActive(visible);
                    }
                }
                else
                {
                    Debug.Log(target);
                    Object.DestroyImmediate(target);
                }
            }
            else
            {
                Stack <GameObject> pool = new Stack <GameObject>();
                mPool[poolName] = pool;

                ToPool(poolName, target, onRevert);
            }
        }
コード例 #2
0
ファイル: AssetsPooling.cs プロジェクト: firefishes/ShipDock
        public void ToPool <T>(int poolName, T target, OnComponentPoolItem <T> onRevert = null, bool visible = false) where T : Component
        {
            if (target == null || mIsDispose)
            {
                return;
            }
            else
            {
            }

            onRevert?.Invoke(target);

            if (mCompPool.IsContainsKey(poolName))
            {
                int elmMax             = mCompPoolElmMax.IsContainsKey(poolName) ? mCompPoolElmMax[poolName] : int.MaxValue;
                Stack <Component> pool = mCompPool[poolName];
                if (pool.Count < elmMax)
                {
                    pool.Push(target);

                    if (PoolContainer != null)
                    {
                        PoolContainer.Collect(target.gameObject, visible);
                    }
                    else
                    {
                        target.gameObject.SetActive(visible);
                    }
                }
                else
                {
                    Object.DestroyImmediate(target.gameObject);
                }
            }
            else
            {
                Stack <Component> pool = new Stack <Component>();
                mCompPool[poolName] = pool;

                ToPool(poolName, target, onRevert);
            }
        }