Esempio n. 1
0
        protected IEnumerator Working()
        {
            m_currIdx = 0;
            Debug.LogFormat("Working, works count:{0}", m_works.Count);
            while (true)
            {
                for (int i = m_working.Count - 1; i >= 0; i--)
                {
                    if (m_working[i].IsFinish)
                    {
                        m_doneNum++;
                        m_working[i].Dispose();
                        m_working.RemoveAt(i);
                    }
                    else
                    {
                        m_working[i].Update();
                    }
                }

                // 有完成的事务 通知外部做表现
                OnWorkProgress(m_doneNum * 1.0f / m_totalCnt);

                if (IsFail)
                {
                    Debug.Log("----有失败任务 停止后续处理----");
                    break;
                }


                // 判断是否全部完成
                if (m_doneNum >= m_totalCnt)
                {
                    break;
                }

                // 有空闲线程 开启新的任务
                int maxNum = m_maxThread - m_working.Count;
                for (int i = 0; i < maxNum && m_currIdx < m_totalCnt; i++)
                {
                    WorkBase work = m_works[m_currIdx];
                    ++m_currIdx;
                    m_working.Add(work);
                    work.Run();
                }
                yield return(null);
            }
            OnWorkDone();
        }
Esempio n. 2
0
        // 任务完成
        protected void DoneWork(WorkBase work)
        {
            int idx = m_works.IndexOf(work);

            m_works.RemoveAt(idx);
        }
Esempio n. 3
0
 // 添加新任务
 protected void AddWork(WorkBase work)
 {
     m_works.Add(work);
 }