コード例 #1
0
ファイル: CObjectPool.cs プロジェクト: Koyatoufu/AbyssHunter
    void UnitPoolCreate(Transform parent, UnitType type, Data.UnitContainer container)
    {
        m_unitPools[type] = new Dictionary <int, UnitPool>();

        for (int i = 0; i < container.GetUnitCount(type); i++)
        {
            CUnitData unitData = container.GetUnitData(type, i);
            if (unitData != null)
            {
                UnitPool pool = new UnitPool();
                pool.unitData      = unitData;
                pool.nBufferAmount = type != UnitType.Boss ? m_unitAmount:1;
                pool.pooledList    = new Stack <GameObject>();

                for (int j = 0; j < pool.nBufferAmount; j++)
                {
                    if (unitData.UnitPrefab == null)
                    {
                        break;
                    }
                    GameObject poolObj = Instantiate(unitData.UnitPrefab);
                    poolObj.name             = unitData.UnitPrefab.name;
                    poolObj.transform.parent = parent;
                    poolObj.SetActive(false);
                    pool.pooledList.Push(poolObj);
                }

                m_unitPools[type].Add(i, pool);
            }
        }
    }
コード例 #2
0
ファイル: CObjectPool.cs プロジェクト: Koyatoufu/AbyssHunter
    void InitUnitPools(Data.UnitContainer container)
    {
        m_unitParent = new GameObject("Units");
        m_unitParent.transform.parent = transform;

        UnitPoolCreate(m_unitParent.transform, UnitType.Npc, container);
        UnitPoolCreate(m_unitParent.transform, UnitType.Enemy, container);
        UnitPoolCreate(m_unitParent.transform, UnitType.Boss, container);
    }