Пример #1
0
    private void DownloadOneFile()
    {
        if (DownloadResInfoQueue.Count <= 0)
        {
            //全部下载完成
            SetState(DownloadResState.saveResInfoList2DownloadingFoler);
            return;
        }
        else
        {
            float downloadProgress = (1f - DownloadResInfoQueue.Count / DownloadFileNum) * 0.9f;//下载从0-0.9f
            Messenger.Broadcast <float>("updateLoadingProgress", downloadProgress);
            Debug.LogError("真下载" + downloadProgress);
        }


        string resRelePath = DownloadResInfoQueue.Dequeue();

        Utils.SB.Append(UpdateMgr.RemoteCdnUrl);
        Utils.SB.Append("/");
        Utils.SB.Append(UnityUtil.CurPlatform);
        Utils.SB.Append(resRelePath);
        string remotePath = Utils.SB.ToString();

        Utils.ClearSB();

        Utils.SB.Append(UnityUtil.PersistentPath);
        Utils.SB.Append(DownloadCachePath);
        Utils.SB.Append(resRelePath);
        string savePath       = Utils.SB.ToString();
        string saveFolderPath = FileHelper.GetDirectorName(savePath);

        FileHelper.CreateFolder(saveFolderPath);
        Utils.ClearSB();

        Action onSuccess = () =>
        {
            LogMgr.I("DownloadRes", "DownloadOneFile", "下载资源成功 remotePath:" + remotePath + " savePath:" + savePath, BeShowLog);
            //下载成功后启动下一次下载
            DownloadOneFile();
        };

        Action <string> onFaile = (error) =>
        {
            LogMgr.E("DownloadRes", "DownloadOneFile", "下载流程中断,下载资源失败 remotePath:" + remotePath + " savePath:" + savePath, BeShowLog);
        };

        Action <int> onGetFileSize = (size) =>
        {
        };

        //单个资源的下载进度
        Action <float> onProgress = (progress) =>
        {
        };

        LogMgr.I("DownloadRes", "DelayDown", "开始下载资源 remotePath:" + remotePath + " savePath:" + savePath + " 剩余待下载资源数:" + DownloadResInfoQueue.Count, BeShowLog);

        DownloadMgr.GetIns().StartDownload(remotePath, savePath, onSuccess, onFaile, onGetFileSize, onProgress);
    }
Пример #2
0
    public void TestDownload(string url)
    {
        string[] URLStr   = url1.Split('/');
        string   FileName = URLStr[URLStr.Length - 1];

        string _savePath = Application.dataPath + "/../" + FileName;

        DownloadMgr.GetIns().StartDownload(url, _savePath, OnSuccess, OnFaile, Total, Progress1);
    }
Пример #3
0
 public void StopDownload(string url)
 {
     DownloadMgr.GetIns().StopDownload(url);
 }