public static void Execute(UnityEditor.BuildTarget target) { string platfrom = AssetBundleController.GetPlatformName(target); Execute(platfrom, "StreamingAssets/clientxml2/"); AssetDatabase.Refresh(); }
public static void ExecuteMd5(UnityEditor.BuildTarget target, string md5FilePath) { string platfrom = AssetBundleController.GetPlatformName(target); Execute(platfrom, md5FilePath); AssetDatabase.Refresh(); }
public static void Execute(UnityEditor.BuildTarget target) { string platform = AssetBundleController.GetPlatformName(target); Execute(platform); AssetDatabase.Refresh(); }
public static void ExecuteDecrypt(UnityEditor.BuildTarget target) { //清空一下缓存 Caching.CleanCache(); string platfrom = AssetBundleController.GetPlatformName(target); string dir = System.IO.Path.Combine(Application.dataPath, "AssetBundle/" + platfrom); foreach (string filePath in Directory.GetFiles(dir)) { if (filePath.Contains(".meta") || filePath.Contains("VersionMD5") || filePath.Contains(".xml") || filePath.Contains(".assetbundle")) { continue; } string key = filePath.Substring(dir.Length + 1, filePath.Length - dir.Length - 1); FileStream file = new FileStream(filePath, FileMode.Open, FileAccess.ReadWrite); byte[] fileData = new byte[file.Length]; byte[] NewHeader = System.Text.Encoding.UTF8.GetBytes("DreamfactionGame"); byte[] NewEnd = System.Text.Encoding.UTF8.GetBytes("zmy"); byte[] buff = new byte[(int)file.Length - NewHeader.Length - NewEnd.Length]; file.Read(fileData, 0, (int)file.Length); for (int i = 0; i < fileData.Length; i++) { if (i >= 0 && i < NewHeader.Length) { //buff[i] = NewHeader[i]; //buff[i] += (byte)i; } else if (i >= NewHeader.Length && i < fileData.Length - NewEnd.Length) { buff[i - NewHeader.Length] = fileData[i]; buff[i - NewHeader.Length] -= 1; } else if (i >= fileData.Length - NewEnd.Length && i < fileData.Length) { //buff[i] = NewEnd[i - fileData.Length]; } } file.Flush(); file.Close(); fileData = null; key = key.Substring(0, key.LastIndexOf('.')); key += ".dec"; FileStream stream = new FileStream(dir + "/" + key, FileMode.Create); stream.Write(buff, 0, buff.Length); stream.Flush(); stream.Close(); buff = null; } AssetDatabase.Refresh(); }
/// <summary> /// 版本文件的assetbundle文件打包 /// </summary> /// <param name="target">目标平台</param> public static void Execute(UnityEditor.BuildTarget target) { string assetPath = "Assets/" + CreateMD5List.ConfigFilePath + AssetBundleController.GetPlatformName(target) + '/' + CampareMD5ToGenerateVersionNum.FileName; string SavePath = BundleConfigManager.SavePath + AssetBundleController.GetPlatformName(target) + "/VersionNum/"; if (!Directory.Exists(SavePath)) { Directory.CreateDirectory(SavePath); } SavePath += "VersionNum.assetbundle"; Object obj = AssetDatabase.LoadMainAssetAtPath(assetPath); BuildPipeline.BuildAssetBundle(obj, null, SavePath, _option, target); AssetDatabase.Refresh(); }
/// <summary> /// assetbundle打包 /// </summary> /// <param name="target">目标平台</param> public static void Execute(UnityEditor.BuildTarget target) { BundleConfigManager.ReadConfig(); Dictionary <string, List <string> > bundles = BundleConfigManager.Bundles; string savePath = BundleConfigManager.SavePath + AssetBundleController.GetPlatformName(target) + '/'; if (!Directory.Exists(savePath)) { Directory.CreateDirectory(savePath); } if (bundles.Count <= 0) { Debug.LogError(BundleConfigManager.ConfigFileName + " is empty."); return; } //打包 foreach (KeyValuePair <string, List <string> > bundle in bundles) { List <Object> objs = new List <Object>(); foreach (string path in bundle.Value) { FillObjToList(path, objs); } BuildPipeline.BuildAssetBundle(objs[0], objs.ToArray(), savePath + bundle.Key + ".assetbundle", _option, target); } //计算MD5 CreateMD5List.Execute(target); //比较MD5 CampareMD5ToGenerateVersionNum.Execute(target); //修改Version文件 CreateAssetBundleForXmlVersion.Execute(target); // scene目录下的资源 AssetDatabase.Refresh(); }
public static void ExecuteEncryption(UnityEditor.BuildTarget target) { //清空一下缓存 Caching.CleanCache(); string platfrom = AssetBundleController.GetPlatformName(target); string dir = System.IO.Path.Combine(Application.dataPath, "StreamingAssets/AssetBundle/" + platfrom); foreach (string filePath in Directory.GetFiles(dir)) { if (filePath.Contains(".meta") || filePath.Contains("VersionMD5") || filePath.Contains(".xml") || filePath.Contains(".enc") || filePath.Contains(".lua")) { continue; } string key = filePath.Substring(dir.Length + 1, filePath.Length - dir.Length - 1); FileStream file = new FileStream(filePath, FileMode.Open, FileAccess.ReadWrite); byte[] fileData = new byte[file.Length]; byte[] NewHeader = System.Text.Encoding.UTF8.GetBytes("DreamfactionGame"); byte[] NewEnd = System.Text.Encoding.UTF8.GetBytes("zmy"); byte[] buff = new byte[(int)file.Length + NewHeader.Length + NewEnd.Length]; file.Read(fileData, 0, (int)file.Length); //对二进制文件添加固定头尾,中端修改内容 for (int i = 0; i < buff.Length; i++) { if (i >= 0 && i < NewHeader.Length) { buff[i] = NewHeader[i]; //buff[i] += (byte)i; } else if (i >= NewHeader.Length && i < fileData.Length + NewHeader.Length) { buff[i] = fileData[i - NewHeader.Length]; buff[i] += 1; } else if (i >= fileData.Length + NewHeader.Length && i < buff.Length) { int randomNum = Random.Range(97, 123); buff[i] = (byte)randomNum; } } file.Flush(); file.Close(); fileData = null; if (File.Exists(filePath)) { File.Delete(filePath); } key = key.Substring(0, key.LastIndexOf('.')); key += ".enc"; string newFilePath = filePath.Substring(0, filePath.LastIndexOf('.')); newFilePath += ".enc"; if (File.Exists(newFilePath)) { // string nMessage = key + "资源有重名,是否覆盖"; // if (EditorUtility.DisplayDialog("", nMessage, "是", "否") == false) // { // EditorUtility.DisplayDialog("", "资源加密已取消,请修改资源名称重新打包", "OK"); // return; // } // else // { // File.Delete(key); // } File.Delete(key); } FileStream stream = new FileStream(dir + "/" + key, FileMode.Create); stream.Write(buff, 0, buff.Length); stream.Flush(); stream.Close(); buff = null; } AssetDatabase.Refresh(); EditorUtility.DisplayDialog("", "资源加密完成", "OK"); }