Exemple #1
0
        /// <summary>
        /// 下载多个文件
        /// </summary>
        /// <param name="lstUrl"></param>
        /// <param name="onDownloadMulitUpdate"></param>
        /// <param name="onDownloadMulitComplete"></param>
        public void BeginDownloadMulit(LinkedList <string> lstUrl, BaseAction <int, int, ulong, ulong> onDownloadMulitUpdate = null, BaseAction onDownloadMulitComplete = null)
        {
            m_OnDownloadMulitUpdate   = onDownloadMulitUpdate;
            m_OnDownloadMulitComplete = onDownloadMulitComplete;

            m_NeedDownloadList.Clear();
            m_DownloadMulitCurrSizeDic.Clear();

            m_DownloadMulitNeedCount = 0;
            m_DownloadMulitCurrCount = 0;

            m_DownloadMulitTotalSize = 0;
            m_DownloadMulitCurrSize  = 0;

            //1.把需要下载的加入下载队列
            for (LinkedListNode <string> item = lstUrl.First; item != null; item = item.Next)
            {
                string url = item.Value;
                AssetBundleInfoEntity entity = GameEntry.Resource.ResourceManager.GetAssetBundleInfo(url);
                if (entity != null)
                {
                    m_DownloadMulitTotalSize += entity.Size;
                    m_DownloadMulitNeedCount++;
                    m_NeedDownloadList.AddLast(url);
                    m_DownloadMulitCurrSizeDic[url] = 0;
                }
                else
                {
                    GameEntry.LogError("无效资源包=>" + url);
                }
            }

            //下载器数量 最多5个
            int routineCount = Mathf.Min(GameEntry.Download.DownloadRoutineCount, m_NeedDownloadList.Count);

            for (int i = 0; i < routineCount; i++)
            {
                DownloadRoutine routine = GameEntry.Pool.DequeueClassObject <DownloadRoutine>();

                string url = m_NeedDownloadList.First.Value;
                m_NeedDownloadList.RemoveFirst();

                AssetBundleInfoEntity entity = GameEntry.Resource.ResourceManager.GetAssetBundleInfo(url);
                routine.BeginDownload(url, entity, OnDownloadMulitUpdate, OnDownloadMulitComplete);
                m_DownloadRoutineList.AddLast(routine);
            }
        }
Exemple #2
0
        /// <summary>
        /// 多文件下载完毕回调
        /// </summary>
        /// <param name="fileUrl"></param>
        /// <param name="routine"></param>
        private void OnDownloadMulitComplete(string fileUrl, DownloadRoutine routine)
        {
            //检查队列中是否有要下载的数据
            if (m_NeedDownloadList.Count > 0)
            {
                //让下载器继续工作
                string url = m_NeedDownloadList.First.Value;
                m_NeedDownloadList.RemoveFirst();
                //Debug.LogError("让下载器继续工作 下载="+ url);

                AssetBundleInfoEntity entity = GameEntry.Resource.ResourceManager.GetAssetBundleInfo(url);
                routine.BeginDownload(url, entity, OnDownloadMulitUpdate, OnDownloadMulitComplete);
            }
            else
            {
                m_DownloadRoutineList.Remove(routine);
                GameEntry.Pool.EnqueueClassObject(routine);
            }

            m_DownloadMulitCurrCount++;

            if (m_OnDownloadMulitUpdate != null)
            {
                m_OnDownloadMulitUpdate(m_DownloadMulitCurrCount, m_DownloadMulitNeedCount, m_DownloadMulitCurrSize, m_DownloadMulitTotalSize);
            }

            if (m_DownloadMulitCurrCount == m_DownloadMulitNeedCount)
            {
                //结束的时候 直接把当前下载的大小设置为总大小
                m_DownloadMulitCurrSize = m_DownloadMulitTotalSize;
                if (m_OnDownloadMulitUpdate != null)
                {
                    m_OnDownloadMulitUpdate(m_DownloadMulitCurrCount, m_DownloadMulitNeedCount, m_DownloadMulitCurrSize, m_DownloadMulitTotalSize);
                }

                if (m_OnDownloadMulitComplete != null)
                {
                    m_OnDownloadMulitComplete();
                }
            }
        }
Exemple #3
0
        /// <summary>
        /// 下载单一文件
        /// </summary>
        /// <param name="url"></param>
        /// <param name="onUpdate"></param>
        /// <param name="onComplete"></param>
        public void BeginDownloadSingle(string url, BaseAction <string, ulong, float> onUpdate = null, BaseAction <string> onComplete = null)
        {
            AssetBundleInfoEntity entity = GameEntry.Resource.ResourceManager.GetAssetBundleInfo(url);

            if (entity == null)
            {
                GameEntry.LogError("无效资源包=>" + url);
                return;
            }

            DownloadRoutine routine = GameEntry.Pool.DequeueClassObject <DownloadRoutine>();

            routine.BeginDownload(url, entity, onUpdate, onComplete: (string fileUrl, DownloadRoutine r) =>
            {
                m_DownloadRoutineList.Remove(r);
                GameEntry.Pool.EnqueueClassObject(routine);
                if (onComplete != null)
                {
                    onComplete(fileUrl);
                }
            });
            m_DownloadRoutineList.AddLast(routine);
        }