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;

            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);
                }
            }

            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
        private void OnDownloadMulitComplete(string fileUrl, DownloadRoutine routine)
        {
            Debug.LogError("下载完毕=" + fileUrl);
            if (m_NeedDownloadList.Count > 0)
            {
                string url = m_NeedDownloadList.First.Value;
                m_NeedDownloadList.RemoveFirst();

                AssetBundleInfoEntity entity = GameEntry.Resource.ResourceManager.GetAssetBundleInfo(url);
                routine.BeginDownload(url, entity, OnDownloadMulitUpdate, OnDownloadMulitComplete);
            }
            else
            {
                m_DownloadRoutineList.Remove(routine);
                Debug.LogError("下载器回池");
                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 rou) =>
            {
                m_DownloadRoutineList.Remove(rou);
                GameEntry.Pool.EnqueueClassObject(routine);

                if (onComplete != null)
                {
                    onComplete(fileUrl);
                }
            });
            m_DownloadRoutineList.AddLast(routine);
        }