예제 #1
0
 // Update is called once per frame
 void Update()
 {
     if (!Ok)
     {
         bool flag = CompareVersion();
         if (flag)
         {
             Bar.Translate(Vector3.right * BarLength, Space.Self);
             DL = new DownLoad();
             GameObject.Find("Canvas/Panel/ProgressBar/Text").GetComponent <Text>().text = "100.0%";
             File.Delete(URL.Download_version);
         }
         return;
     }
     if (DL.Begin && !First)
     {
         //获取到流数据,异步下载数据
         StartCoroutine(DL.download(DL.downloadedFragments));
         DL.Begin = false;
         First    = true;
     }
     Debug.Log("now : " + now + "  sum : " + sum);
     Debug.Log("DL.now : " + DL.now + "  downloadlength : " + DL.downloadlength);
     if (DL.temp != 0)
     {
         //更新UI
         float p = DL.temp / (float)sum;
         Bar.Translate(Vector3.right * p * BarLength, Space.Self);
         now += DL.temp;
         p    = 100f * now / (float)sum;
         GameObject.Find("Canvas/Panel/ProgressBar/Text").GetComponent <Text>().text = p.ToString("f1") + "%";
         DL.temp = 0;
     }
     else if (DL.now == DL.downloadlength)
     {
         if (Cnt + 1 < ToDownload.Count && DL.now != 0)
         {
             Debug.Log("Cnt : " + Cnt);
             //继续下载剩余的文件
             ++Cnt;
             DL = new DownLoad(URL.Server_path + ToDownload[Cnt], URL.Temp_path + ToDownload[Cnt], URL.Local_path + ToDownload[Cnt]);
             DL.StartDownload();
             First = false;
         }
         else if (Cnt + 1 == ToDownload.Count)
         {
             Debug.Log("Finish");
             //更新本地version文件
             Cnt++;
             File.Copy(URL.Download_version, URL.Local_version, true);
             File.Delete(URL.Download_version);
         }
     }
 }