예제 #1
0
        /// <summary>
        ///   下载
        /// </summary>
        bool Download(string assetbundlename)
        {
            lock (lock_obj_)
            {
                var ab = resources_manifest_.Find(assetbundlename);
                if (ab == null)
                {
                    Debug.LogWarning("AssetBundleDownloader.Download - AssetBundleName is invalid.");
                    return(true);
                }

                string file_name = ab.IsCompress ?
                                   Compress.GetCompressFileName(assetbundlename) : assetbundlename;
                if (!IsDownLoading(file_name))
                {
                    HttpAsyDownload d = GetIdleDownload(true);
                    if (d == null)
                    {
                        return(false);
                    }

                    d.Start(Root, file_name, _DownloadNotify, _DownloadError);
                }

                return(true);
            }
        }
        /// <summary>
        ///   开始下载
        /// </summary>
        public bool Start(string root
                          , List <string> assetbundles
                          , ResourcesManifest resources_manifest)
        {
            Abort();

            if (resources_manifest == null)
            {
                Error(emErrorCode.ParameterError);
                return(false);
            }
            if (assetbundles == null || assetbundles.Count == 0)
            {
                IsDone = true;
                return(true);
            }

            IsDone    = false;
            ErrorCode = emErrorCode.None;

            Root = root;
            resources_manifest_    = resources_manifest;
            UncompleteDownloadList = assetbundles;
            CompleteDownloadList.Clear();
            FailedDownloadList.Clear();

            //统计下载数据
            TotalSize     = 0;
            CompletedSize = 0;
            for (int i = 0; i < UncompleteDownloadList.Count; ++i)
            {
                var ab = resources_manifest_.Find(UncompleteDownloadList[i]);
                if (ab != null)
                {
                    if (ab.IsCompress)
                    {
                        TotalSize += ab.CompressSize;
                    }
                    else
                    {
                        TotalSize += ab.Size;
                    }
                }
            }

            //开始下载
            for (int i = 0; i < System.Net.ServicePointManager.DefaultConnectionLimit; ++i)
            {
                HttpAsyDownload d = new HttpAsyDownload(URL);
                downloads_.Add(d);
                var assetbundlename = GetImcomplete();
                if (!string.IsNullOrEmpty(assetbundlename))
                {
                    Download(downloads_[i], assetbundlename);
                }
            }

            return(true);
        }
        /// <summary>
        ///   下载
        /// </summary>
        bool Download(HttpAsyDownload d, string assetbundlename)
        {
            lock (lock_obj_)
            {
                if (string.IsNullOrEmpty(assetbundlename))
                {
                    return(false);
                }
                var ab = resources_manifest_.Find(assetbundlename);
                if (ab == null)
                {
                    Debug.LogWarning("AssetBundleDownloader.Download - AssetBundleName is invalid.");
                    return(true);
                }

                DownloadingList.Add(assetbundlename);

                string file_name = ab.IsCompress ? Compress.GetCompressFileName(assetbundlename) : assetbundlename;
                d.Start(Root, file_name, _DownloadNotify, _DownloadError);
                return(true);
            }
        }
예제 #4
0
        /// <summary>
        /// 初始化下载信息
        /// </summary>
        void InitializeDownload(string root
                                , List <string> assetbundles
                                , ResourcesManifest resources_manifest)
        {
            Root = root;
            ImcompleteDownloads = assetbundles;
            resources_manifest_ = resources_manifest;

            IsDone    = false;
            ErrorCode = emErrorCode.None;
            CompleteDownloads.Clear();
            FailedDownloads.Clear();

            if (ImcompleteDownloads == null)
            {
                ImcompleteDownloads = new List <string>();
            }

            //统计数据
            TotalSize     = 0;
            CompletedSize = 0;
            for (int i = 0; i < ImcompleteDownloads.Count; ++i)
            {
                var ab = resources_manifest_.Find(ImcompleteDownloads[i]);
                if (ab != null)
                {
                    if (ab.IsCompress)
                    {
                        TotalSize += ab.CompressSize;
                    }
                    else
                    {
                        TotalSize += ab.Size;
                    }
                }
            }
        }