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); } }
static IEnumerator StartLoadManifest(UnityEditor.BuildTarget target) { string platform = AssetBundleCtrl_Windows.GetPlatformName(target); string dir = "file:///" + System.IO.Path.Combine(Application.dataPath, "AssetBundle/" + platform) + "AllResources"; WWW www = new WWW(dir); yield return(www); if (!string.IsNullOrEmpty(www.error)) { yield break; } UnityEngine.Object[] obj = www.assetBundle.LoadAllAssets(); m_abmanifest = obj[0] as AssetBundleManifest; if (m_abmanifest != null) { Execute(platform); } www.assetBundle.Unload(true); if (successCallback != null) { successCallback(true); } //Debug.Log("Create Hash File Success"); // EditorUtility.DisplayDialog("", "生成资源Hash文件完成", "OK"); }
public static void Execute(UnityEditor.BuildTarget target) { string platform = AssetBundleCtrl_Windows.GetPlatformName(target); string newVersionHash = System.IO.Path.Combine(Application.dataPath, "AssetBundle/" + platform + "/VersionNum/VersionHash.xml"); string oldVersionHash = System.IO.Path.Combine(Application.dataPath, "AssetBundle/" + platform + "/VersionNum/VersionHash-old.xml"); SortedList <string, AssetInfo> dicNewHashInfo = CreateHashList.ReadHashFile(newVersionHash); SortedList <string, AssetInfo> dicOldHashInfo = new SortedList <string, AssetInfo>(); if (File.Exists(oldVersionHash)) { dicOldHashInfo = CreateHashList.ReadHashFile(oldVersionHash); } string versionUpdateFile = System.IO.Path.Combine(Application.dataPath, "AssetBundle/" + platform + "/VersionNum/VersionUpdateList.bytes"); IndexFileData data = new IndexFileData(); data.mVersion = "0.01"; foreach (KeyValuePair <string, AssetInfo> newPair in dicNewHashInfo) { if (string.Compare(newPair.Key, "AllResources") == 0) { continue; } if (dicOldHashInfo.ContainsKey(newPair.Key)) { if (newPair.Value.hash128 != dicOldHashInfo[newPair.Key].hash128) { data.dataMap[newPair.Value.fileName] = new IndexData() { path = newPair.Value.fileName, hash = newPair.Value.hash128 }; } } else { data.dataMap[newPair.Value.fileName] = new IndexData() { path = newPair.Value.fileName, hash = newPair.Value.hash128 }; } } //增加AssetbundleManifest data.dataMap["AllResources"] = new IndexData() { path = "AllResources", hash = "nohash" }; File.WriteAllText(versionUpdateFile, data.ToString()); AssetDatabase.Refresh(); }
void IncrementalGUI() { //增量包按钮 GUILayout.Label("增量包:"); GUILayout.BeginHorizontal(); GUILayout.Space(80); if (GUILayout.Button("一键打包: [增量]资源包", GUILayout.Width(300), GUILayout.Height(30))) { //开始打包 CreateAssetBundle_Editor.Execute(buildTarget); //生成hash CreateHashList.StartLoad((bool issuccess) => { EditorUtility.DisplayDialog("", "打包成功", "OK"); }); } GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Space(80); if (GUILayout.Button("生成服务端增量文件", GUILayout.Width(300), GUILayout.Height(30))) { mEditorVersion = new VersionCtrl_Editor(); mEditorVersion.mResServerAddress = "http://api-resource.ptdev.cn/v1/res"; //获取上个版本的hash string platform = AssetBundleCtrl_Windows.GetPlatformName(buildTarget); string newVersionHash = System.IO.Path.Combine(Application.dataPath, "AssetBundle/" + platform + "/VersionNum/VersionHash-old.xml"); //将服务器的hash写到本地 mEditorVersion.Start("3", "100", "V0uFhE2GRNnRipS0hery9OhY", newVersionHash, (bool issuccess) => { if (issuccess) { mTaskQue.Enqueue(() => { CreateVersionUpdateList.Execute(buildTarget); EditorUtility.DisplayDialog("", "生成成功", "OK"); }); } else { mTaskQue.Enqueue(() => { EditorUtility.DisplayDialog("", "生成失败", "OK"); }); } }); } if (mTaskQue.Count > 0) { var action = mTaskQue.Dequeue(); action(); } GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Space(80); if (GUILayout.Button("一键导出", GUILayout.Width(300), GUILayout.Height(30))) { var outpath = EditorUtility.OpenFolderPanel("选择导出文件夹", "", ""); if (outpath != null && outpath != "") { CreateVersionUpdateList.ExportFile(buildTarget, outpath); EditorUtility.DisplayDialog("", buildTarget.ToString() + "- 导出到" + outpath + "成功", "OK"); } } GUILayout.EndHorizontal(); }