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(); }
public void Update() { CreateHashList.Update(buildTarget); }
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(); }