示例#1
0
        /// <summary>
        /// 从列表尾部获取一个闲置的单元,如果不存在则创建一个新的
        /// </summary>
        /// <returns>闲置单元</returns>
        public TT GetIdleUnit <TT>() where TT : T
        {
            TT unit = null;

            if (idleList.Count > 0)
            {
                while (idleList.Count > 0 && idleList[idleList.Count - 1] == null)
                {
                    idleList.RemoveAt(idleList.Count - 1);
                }
                if (idleList.Count > 0)
                {
                    unit = (TT)idleList[idleList.Count - 1];
                    idleList.RemoveAt(idleList.Count - 1);
                }
            }
            if (unit == null)
            {
                unit = CreateNewUnit <TT>();
                unit.SetParentList(this);
                m_createdNum++;
            }
            workList.Add(unit);
            unit.unitStatu = PoolUnitStatuType.Work;
            OnUnitChangePool(unit);
            return(unit);
        }