void HandlePatchPackageData(List <PatchPackage> patchList)
        {
            if (checkState != null)
            {
                checkState.text = "检查更新...";
            }

            string localPersistentPath = BundleConfig.Instance.BundlesPathForPersist;

            if (!Directory.Exists(localPersistentPath))
            {
                Directory.CreateDirectory(localPersistentPath);
            }

            List <DownLoadFile> updateList = new List <DownLoadFile>();

            for (int i = 0; i < patchList.Count; i++)
            {
                DownLoadFile df = new DownLoadFile();
                df.remoteFile = patchList[i].url;
                UnityEngine.Debug.Log(string.Format("downFileIndex: {0}, remoteUrl: {1}", i, df.remoteFile));
                df.localFile = string.Format("{0}patch_{1}.zip", localPersistentPath, patchList[i].ver.Replace('.', '_'));
                df.totalSize = long.Parse(patchList[i].size);
                df.size      = df.totalSize - ThreadDownLoad.GetSize(df.localFile);
                df.md5       = patchList[i].md5;
                if (df.size == 0)
                {
                    UnityEngine.Debug.LogWarning("3333");
                    df.isDownFinished = true;
                }


                if (updateList == null)
                {
                    updateList = new List <DownLoadFile>();
                }
                updateList.Add(df);
                allSize += df.size;
            }

            if (checkState != null)
            {
                checkState.gameObject.SetActive(false);
            }

            if (allSize > 0 && updateList.Count > 0)
            {
                showMsg("取消", delegate { closeMessageBox(); Application.Quit(); },
                        string.Format("发现游戏有更新,需要下载{0}的更新包", getSize(allSize)),
                        "确定", delegate { closeMessageBox(); startUpdateAssets(updateList); });
            }
            else
            {
                if (unZipCor != null)
                {
                    StopCoroutine(unZipCor);
                }
                unZipCor = StartCoroutine(unZip(updateList));
            }
        }
 /// <summary>
 /// 通知表现层发生的数据变化
 /// </summary>
 /// <param name="data">当前下载数据</param>
 private void OnSyncEvent(DownLoadFile data)
 {
     if (callback != null)
     {
         callback(data);
     }
 }
 /// <summary>
 /// 添加到事件队列
 /// </summary>
 public void AddEvent(DownLoadFile ev, Action <DownLoadFile> func)
 {
     lock (m_lockObj)
     {
         callback = func;
         downloadsQueue.Enqueue(ev);
     }
 }
 void OnDownLoad(DownLoadFile df)
 {
     if (df.isDownFinished)
     {
         isDownLoading = false;
     }
     else
     {
         timeoutSw.Reset();
         timeoutSw.Start();
     }
 }
        /// <summary>
        /// 开始下载文件
        /// </summary>
        /// <param name="curDF">当前要下载的文件信息</param>
        private void httpDownFile(DownLoadFile curDF)
        {
            UnityEngine.Debug.Log("--httpDownFile-->" + curDF.remoteFile);
            //打开网络连接
            try
            {
                if (!curDF.isDownFinished)
                {
                    HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(new Uri(curDF.remoteFile));

                    if (File.Exists(curDF.localFile))
                    {
                        if (curDF.fs != null)
                        {
                            curDF.fs.Close();
                            curDF.fs.Dispose();
                            curDF.fs = null;
                        }

                        Stream fs = File.OpenWrite(curDF.localFile);
                        //移动文件流中的当前指针
                        fs.Seek(fs.Length, SeekOrigin.Current);
                        request.AddRange((int)fs.Length);
                        curDF.fs = fs;
                    }
                    else
                    {
                        Stream fs = File.Open(curDF.localFile, FileMode.Create);

                        curDF.fs = fs;
                    }

                    curDF.request = request;

                    request.BeginGetResponse(new AsyncCallback(httpDownFileCallBack), curDF);
                }
            }
            catch (Exception ex)
            {
                UnityEngine.Debug.LogError("--httpDownFile-->" + ex.ToString());
                if (curDF.fs != null)
                {
                    curDF.fs.Close();
                    curDF.fs.Dispose();
                }

                if (curDF.request != null)
                {
                    curDF.request.Abort();
                    curDF.request = null;
                }
            }
        }
 /// <summary>
 /// 线程方法
 /// </summary>
 void OnUpdate()
 {
     while (true)
     {
         lock (m_lockObj)
         {
             if (downloadsQueue.Count > 0)
             {
                 DownLoadFile e = downloadsQueue.Dequeue();
                 try
                 {
                     //下载文件
                     httpDownFile(e);
                 }
                 catch (System.Exception ex)
                 {
                     UnityEngine.Debug.LogError(ex.Message);
                 }
             }
         }
         Thread.Sleep(1);
     }
 }
 void BeginDownLoad(DownLoadFile df)
 {
     threadDownLoad.AddEvent(df, OnDownLoad);
     isDownLoading = true;
 }
        private void httpDownFileCallBack(IAsyncResult asynchronousResult)
        {
            DownLoadFile    df       = null;
            Stream          ns       = null;
            HttpWebResponse response = null;

            try
            {
                df       = (DownLoadFile)asynchronousResult.AsyncState;
                response = (HttpWebResponse)(df.request.EndGetResponse(asynchronousResult));

                ns = response.GetResponseStream();

                byte[] nbytes    = new byte[bufferbytes];
                int    nReadSize = 0;
                nReadSize = ns.Read(nbytes, 0, bufferbytes);
                while (nReadSize > 0)
                {
                    if (BeingAssetUpdate && df.fs != null)
                    {
                        df.downSize += nReadSize;                    //已经下载大小
                        df.fs.Write(nbytes, 0, nReadSize);           //写文件
                        nReadSize = ns.Read(nbytes, 0, bufferbytes); //继续读流
                        if (m_SyncEvent != null)
                        {
                            m_SyncEvent(df);
                        }
                    }
                }

                if (df.downSize == df.size)
                {
                    df.isDownFinished = true;
                    if (m_SyncEvent != null)
                    {
                        m_SyncEvent(df);
                    }
                }

                if (df.fs != null)
                {
                    df.fs.Close();
                    df.fs.Dispose();
                    df.fs = null;
                }

                if (ns != null)
                {
                    ns.Close();
                    ns.Dispose();
                }

                if (df.request != null)
                {
                    df.request.Abort();
                    df.request = null;
                }

                if (response != null)
                {
                    response.Close();
                    response = null;
                }
            }
            catch (Exception ex)
            {
                if (df != null)
                {
                    if (df.fs != null)
                    {
                        df.fs.Close();
                        df.fs.Dispose();
                        df.fs = null;
                    }

                    if (df.request != null)
                    {
                        df.request.Abort();
                        df.request = null;
                    }
                }

                if (response != null)
                {
                    response.Close();
                    response = null;
                }
                UnityEngine.Debug.LogWarning("httpDownFileCallBack --ex-->" + ex.ToString() + "<--LocalFile-->" + df.localFile);
            }
        }