Exemple #1
0
    public static void ExportFile(UnityEditor.BuildTarget target, string copyto)
    {
        string platform   = AssetBundleCtrl_Windows.GetPlatformName(target);
        string file       = System.IO.Path.Combine(Application.dataPath, "AssetBundle/" + platform);
        var    updatalist = file + "/VersionNum/VersionUpdateList.bytes";

        if (File.Exists(updatalist) == false)
        {
            EditorUtility.DisplayDialog("", updatalist + " 不存在,\n请生成 增量包文件!(第二个按钮)", "OK");
            return;
        }

        var data = IndexFileData.Create(File.ReadAllBytes(updatalist));

        copyto += ("/" + platform);

        if (Directory.Exists(copyto))
        {
            Directory.Delete(copyto, true);
        }
        Directory.CreateDirectory(copyto);

        //拷贝版本描述文件
        File.Copy(Path.Combine(file, "VersionNum/VersionHash.xml"), Path.Combine(copyto, "VersionHash.xml"), true);
        File.Copy(Path.Combine(file, "VersionNum/VersionUpdateList.bytes"), Path.Combine(copyto, "VersionUpdateList.bytes"), true);

        foreach (var d in data.dataMap)
        {
            File.Copy(Path.Combine(file, d.Value.path), Path.Combine(copyto, d.Value.path), true);
        }
    }
    /// <summary>
    /// 根据服务端列表创建资源下载队列
    /// </summary>
    /// <param name="httppath"></param>
    /// <param name="indexdata"></param>
    /// <param name="processCallback"></param>
    private void CreateCurVersionResTaskQue(string httppath, byte[] indexdata, Action <float, string, bool> processCallback)
    {
        var data = IndexFileData.Create(indexdata);

        foreach (var d in data.dataMap.Values)
        {
            resDownloadTaskQue.Enqueue(HttpMgr.Task.Create(httppath + "/" + GetPlatformName() + "/" + d.path, null, (HttpMgr.Task task, WWW w) =>
            {
                Debug.Log("下载资源:" + task.url);
                if (w.error != null)    //判断是不是发生异常
                {
                    //写入
                    if (Directory.Exists(mLocalHotUpdateResPath) == false)
                    {
                        Directory.CreateDirectory(mLocalHotUpdateResPath);
                    }
                    //
                    string path = Path.Combine(mLocalHotUpdateResPath, Path.GetFileName(task.url));
                    if (File.Exists(path))
                    {
                        File.Delete(path);
                    }

                    File.WriteAllBytes(path, w.bytes);

                    //继续当前版本下载任务
                    if (resDownloadTaskQue.Count > 0)
                    {
                        var _task = resDownloadTaskQue.Dequeue();
                        HttpMgr.Instance.GetLayer((uint)HttpLayer.HotUpdate).QueueTask(_task);
                    }

                    else     //当前任务全部下载完
                    {
                        //开始下一个版本
                        DoNextVersionTask(processCallback);
                    }
                }
                else
                {
                    processCallback(-1, "网络出错:" + w.error, false);
                    Debug.LogError(w.error);
                    return;
                }
            }));
        }
    }