public static void ExportPublic() { ExportAssetBundle.BuildAssetBundles(); AssetDatabase.Refresh(); ExportAssetBundle.ExportLua(); AssetDatabase.Refresh(); ExportAssetBundle.GenerateResPublic(CurrentBundleVersion.versionCode.ToString()); }
public static void ExportLuaEx(string dirPath) { string tmpPath = Path.GetFullPath(Path.Combine(Application.dataPath, "tmp")); DirectoryDelete(tmpPath); CheckDirectory(tmpPath); string[] include = new string[] { ".lua", ".cs", ".txt", ".shader", ".py" }; List <string> exportNames = new List <string>(); string[] fileList = Directory.GetFiles(dirPath, "*.*", SearchOption.AllDirectories); for (int i = 0; i < fileList.Length; i++) { string fileName = fileList[i]; string ext = Path.GetExtension(fileName); if (Array.IndexOf <string>(include, ext) != -1) { string byteFileName = fileName.Replace(dirPath, ""); if (byteFileName.StartsWith("\\")) { byteFileName = byteFileName.Substring(1); } byteFileName = byteFileName.Replace("\\", "%").Replace("/", "%").Replace(".", "%"); byteFileName += ".bytes"; exportNames.Add("Assets/tmp/" + byteFileName); File.Copy(Path.GetFullPath(fileName), Path.Combine(tmpPath, byteFileName), true); } } System.Threading.Thread.Sleep(1000); AssetDatabase.Refresh(); ExportAssetBundle.BuildAssetBundles(exportNames.ToArray(), "Assets/tmp", "luaout.bytes", BuildAssetBundleOptions.DeterministicAssetBundle); string strOutputPath = Path.Combine(Application.streamingAssetsPath, PathUtil.Platform); CheckDirectory(strOutputPath); string luaoutPath = Path.Combine(Application.dataPath, "tmp/luaout.bytes"); string luaExportPath = Path.GetFullPath(Path.Combine(strOutputPath, "lua_core.u3d")); byte[] by = File.ReadAllBytes(luaoutPath); byte[] encrypt = CryptographHelper.Encrypt(by, key, iv); File.WriteAllBytes(luaExportPath, encrypt); DirectoryDelete(tmpPath); Debug.Log(luaExportPath + " export."); System.Threading.Thread.Sleep(100); AssetDatabase.Refresh(); }
public static void ExportAllAssetBundle() { string strOutputPath = Path.GetFullPath(Path.Combine(Application.streamingAssetsPath, PathUtil.Platform)); DirectoryInfo dir = new DirectoryInfo(strOutputPath); if (dir.Exists) { dir.Delete(true); } ExportAssetBundle.BuildAssetBundles(); ExportAssetBundle.ExportLua(); }
private static void SetAssetName(string strPath) { foreach (string path in prefab_path) { if (strPath.StartsWith(path)) { if (strPath.EndsWith(".prefab")) { Object obj = PrefabUtility.LoadPrefabContents(strPath); ExportAssetBundle.SetAssetBundleNameByDirectory(strPath, obj); } else if (strPath.EndsWith(".asset")) { Object obj = AssetDatabase.LoadAssetAtPath(strPath, typeof(ScriptableObject)); ExportAssetBundle.SetAssetBundleNameByDirectory(strPath, obj); } break; } } }
private static void GenericBuild(string[] scenes, string target_dir, BuildTarget build_target, BuildOptions build_options) { AssetDatabase.Refresh(); bool needEncrypt = false; if (needEncrypt) { string strOutputPath = Path.GetFullPath(Path.Combine(Application.streamingAssetsPath, PathUtil.Platform)); DirectoryInfo dir = new DirectoryInfo(strOutputPath); if (dir.Exists) { dir.Delete(true); } AssetDatabase.Refresh(); GenerateObfuscatedCode.GenerateCodes(); AssetDatabase.Refresh(); } ExportAssetBundle.BuildAssetBundles(); ExportAssetBundle.ExportLua(); if (needEncrypt) { ExportAssetBundle.EncryptAssetBundle(); } ExportAssetBundle.GenerateVersion(); BuildReport res = BuildPipeline.BuildPlayer(scenes, target_dir, build_target, build_options); BuildSummary summary = res.summary; if (summary.result == BuildResult.Failed) { throw new Exception("BuildPlayer failure: " + res.ToString()); } }
public static void EncodeLuaFile() { ExportAssetBundle.EncodeLuaFile(); }
public static void CleanLocalFile() { PlayerPrefs.DeleteKey(GameConfig.LocalResVersionKey); PlayerPrefs.DeleteKey(GameConfig.LocalSubVersionKey); ExportAssetBundle.CleanLocalFile(); }
public static void ExportLua() { string path = Path.GetFullPath(Path.Combine(Application.dataPath, "Lua")); string tmpPath = Path.GetFullPath(Path.Combine(Application.dataPath, "tmp")); DirectoryDelete(tmpPath); CheckDirectory(tmpPath); List <string> sourceFiles = new List <string>(); List <string> exportNames = new List <string>(); List <string> files = getAllChildFiles(path, "lua"); foreach (string filePath in files) { string file = Path.GetFullPath(filePath); if (!file.EndsWith(".lua")) { continue; } string byteFileName = file.Replace(path, ""); if (byteFileName.StartsWith("\\") || byteFileName.StartsWith("/")) { byteFileName = byteFileName.Substring(1); } byteFileName = byteFileName.Replace(".lua", ".bytes").Replace("\\", "_").Replace("/", "_"); exportNames.Add("Assets/tmp/" + byteFileName); //File.Copy(file, Path.Combine(tmpPath, byteFileName), true); string srcFile = file.Replace(Path.GetFullPath(Application.dataPath), ""); srcFile = "Assets" + srcFile; Debug.Log(srcFile); sourceFiles.Add(srcFile); } //打包config string cfgPath = Path.GetFullPath(Path.Combine(Application.dataPath, "Config/config")); Debug.Log("Export Lua Path:" + cfgPath); List <string> cfgFiles = getAllChildFiles(cfgPath, "lua"); foreach (string filePath in cfgFiles) { string file = Path.GetFullPath(filePath); if (!file.EndsWith(".lua")) { continue; } string byteFileName = file.Replace(cfgPath, ""); if (byteFileName.StartsWith("\\") || byteFileName.StartsWith("/")) { byteFileName = byteFileName.Substring(1); } byteFileName = byteFileName.Replace(".lua", ".bytes").Replace("\\", "_").Replace("/", "_"); byteFileName = "config_" + byteFileName; exportNames.Add("Assets/tmp/" + byteFileName); //File.Copy(file, Path.Combine(tmpPath, byteFileName), true); string srcFile = file.Replace(Path.GetFullPath(Application.dataPath), ""); srcFile = "Assets" + srcFile; sourceFiles.Add(srcFile); } System.Threading.Thread.Sleep(1000); AssetDatabase.Refresh(); JITBUILDTYPE jbt = GetLuaJitBuildType(EditorUserBuildSettings.activeBuildTarget); SLua.LuajitGen.compileLuaJit(sourceFiles.ToArray(), exportNames.ToArray(), jbt); System.Threading.Thread.Sleep(1000); AssetDatabase.Refresh(); ExportAssetBundle.BuildAssetBundles(exportNames.ToArray(), "Assets/tmp", "luaout.bytes", optionsDefault); string strOutputPath = Path.Combine(Application.streamingAssetsPath, PathUtil.Platform); CheckDirectory(strOutputPath); string luaoutPath = Path.Combine(Application.dataPath, "tmp/luaout.bytes"); string luaExportPath = Path.GetFullPath(Path.Combine(strOutputPath, "lua.u3d")); byte[] by = File.ReadAllBytes(luaoutPath); byte[] encrypt = CryptographHelper.Encrypt(by, KeyVData.Instance.KEY, KeyVData.Instance.IV); File.WriteAllBytes(luaExportPath, encrypt); DirectoryDelete(tmpPath); Debug.Log(luaExportPath + " export."); System.Threading.Thread.Sleep(100); AssetDatabase.Refresh(); }
public static void GenerateVersion() { ExportAssetBundle.GenerateVersion(); }
static void GenerateDES() { ExportAssetBundle.GenerateKey(); }
public static void BuildAssetBundles() { ExportAssetBundle.BuildAssetBundles(); }
public static void BuildSelectAssetBundleForWindows32() { ExportAssetBundle.CreateAssetBundleSelect_Win32(); }
public static void Build_AssetBundle_Multiple_Windows64() { ExportAssetBundle.CreateAssetBundleSelectToOne_Windows64(); }
public static void Build_AssetBundle_Multiple_Android() { ExportAssetBundle.CreateAssetBundleSelectToOne_Android(); }
public static void BuildAllAssetBundleForWindows32() { ExportAssetBundle.CreateAssetBundleAll_Win32(); }
public static void ExportiPhonePublic(string subBucket = null) { string[] args = System.Environment.GetCommandLineArgs(); if (args == null || args.Length == 0) { return; } Debug.Log("ExportiPhonePublic: " + string.Join(", ", args)); List <string> fileList = new List <string>(); List <string> versionList = new List <string>(); Regex regExp = new Regex(@"^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$"); foreach (string fileName in args) { if (fileName.EndsWith(".u3d")) { fileList.Add(fileName); } else { if (regExp.IsMatch(fileName)) { string bundleVersionCode = BundleVersionChecker.BundleVersion2Code(fileName); if (!versionList.Contains(bundleVersionCode)) { versionList.Add(bundleVersionCode); } } } } EditorUserBuildSettings.SwitchActiveBuildTarget(BuildTargetGroup.iOS, BuildTarget.iOS); string bundleVersion = args[args.Length - 3]; PlayerSettings.bundleVersion = bundleVersion; PlayerSettings.iOS.buildNumber = args[args.Length - 2]; BundleVersionChecker.UpdateBundleVersion(); AssetDatabase.Refresh(); ExportAssetBundle.BuildAssetBundles(); AssetDatabase.Refresh(); ExportAssetBundle.ExportLua(); AssetDatabase.Refresh(); string folder = args[args.Length - 1]; foreach (string bundleVersionCode in versionList) { string outFolderName = PathUtil.Platform + bundleVersionCode; if (!string.IsNullOrEmpty(subBucket)) { outFolderName = subBucket + "/" + outFolderName; } string strOut = Path.GetFullPath(Path.Combine(folder, outFolderName)); if (Directory.Exists(strOut) == false) { Directory.CreateDirectory(strOut); } Debug.Log("资源导出目录:" + strOut); ExportAssetBundle.GenerateResPublic(bundleVersionCode, strOut, fileList.ToArray()); } }
public static void ExportAndroidLuaPublic(string subBucket = null) { string[] args = System.Environment.GetCommandLineArgs(); if (args == null || args.Length == 0) { return; } Debug.Log(string.Join(",", args)); List <string> fileList = new List <string>(); List <string> versionList = new List <string>(); Regex regExp = new Regex(@"^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$"); foreach (string fileName in args) { if (fileName.EndsWith(".u3d")) { fileList.Add(fileName); } else { if (regExp.IsMatch(fileName)) { string bundleVersionCode = BundleVersionChecker.BundleVersion2Code(fileName); if (!versionList.Contains(bundleVersionCode)) { versionList.Add(bundleVersionCode); } } } } EditorUserBuildSettings.SwitchActiveBuildTarget(BuildTargetGroup.Android, BuildTarget.Android); //PlayerSettings.bundleIdentifier = "xin.unwrap.xiami"; string bundleVersion = args[args.Length - 2]; PlayerSettings.bundleVersion = bundleVersion; //PlayerSettings.SetPropertyInt("ScriptingBackend", (int)ScriptingImplementation.IL2CPP, BuildTarget.Android); BundleVersionChecker.UpdateBundleVersion(); AssetDatabase.Refresh(); ExportAssetBundle.BuildAssetBundles(); AssetDatabase.Refresh(); ExportAssetBundle.ExportLua(); AssetDatabase.Refresh(); string folder = args[args.Length - 1]; foreach (string bundleVersionCode in versionList) { string outFolderName = PathUtil.Platform + bundleVersionCode; if (!string.IsNullOrEmpty(subBucket)) { outFolderName = subBucket + "/" + outFolderName; } string strOut = Path.GetFullPath(Path.Combine(folder, outFolderName)); if (Directory.Exists(strOut) == false) { Directory.CreateDirectory(strOut); } Debug.Log("导出目录:" + strOut); ExportAssetBundle.GenerateDataPublic(strOut, fileList.ToArray()); } }
public static void EncodeCSharpFile() { ExportAssetBundle.EncodeCSharpFile(); }
public static void DecryptAssetBundle() { ExportAssetBundle.EncryptAssetBundle(); }
public static void BuildAllAssetBundleForAndroid() { ExportAssetBundle.CreateAssetBundleAll_Android(); }
public static void SetAssetBundlesNameByDirectory() { ExportAssetBundle.SetAssetBundlesNameByDirectory(); }
public static void GenerateVersion() { string strFilePath = Path.GetFullPath(Path.Combine(Application.streamingAssetsPath, PathUtil.Platform)); string outFolderPath = Path.GetFullPath(string.Concat(Application.dataPath, "/Update/", PathUtil.Platform)); if (Directory.Exists(outFolderPath) == false) { Directory.CreateDirectory(outFolderPath); } Debug.Log("版本号文件名称:" + ExportAssetBundle.VersionTxtName(CurrentBundleVersion.versionCode.ToString())); string strVersionFilePath = Path.Combine(outFolderPath, ExportAssetBundle.VersionTxtName(CurrentBundleVersion.versionCode.ToString())); Dictionary <string, string> fileVersion = new Dictionary <string, string>(); string[] fileList = Directory.GetFiles(strFilePath, "*.*", SearchOption.AllDirectories); for (int i = 0; i < fileList.Length; i++) { string fileName = fileList[i]; if (fileName.Contains(".manifest") || fileName.Contains(".meta") || fileName.Contains(".DS_Store")) { continue; } string filePath = Path.GetFullPath(fileName); EditorUtility.DisplayProgressBar("生成版本号", filePath, (float)i / (float)fileList.Length); byte[] bytes = File.ReadAllBytes(filePath); string strFileVersion = System.Convert.ToString(CRC32.GetCRC32(bytes), 16).ToUpper(); while (8 - strFileVersion.Length > 0) { strFileVersion = "0" + strFileVersion; } filePath = filePath.Replace("\\", "/"); strFilePath = strFilePath.Replace("\\", "/"); string strFileKey = filePath.Replace(strFilePath + "/", ""); //strFileKey = strFileKey.Replace("\\", "/"); fileVersion[strFileKey] = strFileVersion; } StringBuilder content = new StringBuilder(); foreach (KeyValuePair <string, string> kv in fileVersion) { content.AppendLine(kv.Key + "=" + kv.Value); } using (StreamWriter writer = new StreamWriter(strVersionFilePath, false)) { try { writer.WriteLine("{0}", content.ToString()); } catch (System.Exception ex) { string msg = " threw:\n" + ex.ToString(); Debug.LogError(msg); } } EditorUtility.ClearProgressBar(); Debug.Log("生成:" + strVersionFilePath); //EditorUtility.DisplayDialog("提示", "当前文件版本号生成成功", "确定"); AssetDatabase.Refresh(); }
public static void ExportLua() { ExportAssetBundle.ExportLua(); }
public static void ExportLuaPublic() { ExportAssetBundle.ExportLua(); AssetDatabase.Refresh(); ExportAssetBundle.GenerateDataPublic(); }
static void ExportBundle() { ExportAssetBundle.BuildBundle(); }
public static void GenerateResPublic(string versionCode, string dataOutFolderPath = null, string[] otherFileList = null) { string strFilePath = Path.GetFullPath(Path.Combine(Application.streamingAssetsPath, PathUtil.Platform)); string outFolderPath = Path.GetFullPath(string.Concat(Application.dataPath, "/Update/", PathUtil.Platform)); string outDataFolderPath = Path.Combine(outFolderPath, "data"); if (Directory.Exists(outDataFolderPath)) { try { Directory.Delete(outDataFolderPath, true); } catch { } } else { Directory.CreateDirectory(outDataFolderPath); } //当前版本文件的版本号 SortedList <string, string> currentFileVersion = new SortedList <string, string>(); string strVersionFilePath = Path.Combine(outFolderPath, ExportAssetBundle.VersionTxtName(versionCode)); if (!File.Exists(strVersionFilePath)) { string versionCodeBase = string.Empty; versionCodeBase = versionCode[0].ToString() + versionCode[1].ToString() + "00"; Debug.Log("versionCodeBase:" + versionCodeBase); strVersionFilePath = Path.Combine(outFolderPath, ExportAssetBundle.VersionTxtName(versionCodeBase)); } Debug.Log("当前处理的版本号:" + versionCode + ", 当前版本文件:" + strVersionFilePath); if (File.Exists(strVersionFilePath)) { byte[] cfgBytes = File.ReadAllBytes(strVersionFilePath); if (cfgBytes != null) { string configText = System.Text.Encoding.Default.GetString(cfgBytes); StringReader sr = new StringReader(configText); string line = string.Empty; string[] results; while ((line = sr.ReadLine()) != null) { if (!string.IsNullOrEmpty(line)) { results = line.Split('='); if (results.Length >= 2) { currentFileVersion[results[0]] = results[1]; } } } } } SortedList <string, string> fileVersion = new SortedList <string, string>(); string[] fileList = Directory.GetFiles(strFilePath, "*.*", SearchOption.AllDirectories); bool newUpdate = false; for (int i = 0; i < fileList.Length; i++) { string fileName = fileList[i]; if (fileName.Contains(".manifest") || fileName.Contains(".meta") || fileName.Contains(".DS_Store")) { continue; } string filePath = Path.GetFullPath(fileName); filePath = filePath.Replace("\\", "/"); EditorUtility.DisplayProgressBar("生成版本号", filePath, (float)i / (float)fileList.Length); byte[] bytes = File.ReadAllBytes(filePath); string strFileVersion = System.Convert.ToString(CRC32.GetCRC32(bytes), 16).ToUpper(); while (8 - strFileVersion.Length > 0) { strFileVersion = "0" + strFileVersion; } strFilePath = strFilePath.Replace("\\", "/"); string strFileKey = filePath.Replace(strFilePath + "/", ""); fileVersion[strFileKey] = strFileVersion; if (currentFileVersion.ContainsKey(strFileKey) == false || (currentFileVersion[strFileKey] != fileVersion[strFileKey])) { //需要更新的文件,拷贝到Update目录下 FileInfo fi = new FileInfo(Path.Combine(outDataFolderPath, strFileKey)); if (!fi.Directory.Exists) { fi.Directory.Create(); } if (filePath.Contains("bootstrap/bootstrap.u3d")) { continue; } //Debug.Log("更新的文件:" + filePath); newUpdate = true; File.Copy(filePath, fi.FullName, true); } } EditorUtility.ClearProgressBar(); if (otherFileList != null) { for (int i = 0; i < otherFileList.Length; i++) { string fileName = otherFileList[i]; string filePath = Path.GetFullPath(Path.Combine(strFilePath, fileName)); if (!File.Exists(filePath)) { return; } FileInfo fi = new FileInfo(Path.Combine(outDataFolderPath, fileName)); if (!fi.Directory.Exists) { fi.Directory.Create(); } File.Copy(filePath, fi.FullName, true); newUpdate = true; } } if (newUpdate) { System.Threading.Thread.Sleep(1000); AssetDatabase.Refresh(); if (string.IsNullOrEmpty(dataOutFolderPath)) { dataOutFolderPath = GetOutFolderPath(); } if (string.IsNullOrEmpty(dataOutFolderPath)) { return; } CheckDirectory(dataOutFolderPath); cleanMeta(outDataFolderPath); string dataOutPath = Path.Combine(dataOutFolderPath, "res.zip"); FileUtil.PackFiles(dataOutPath, outDataFolderPath); AssetDatabase.Refresh(); System.Threading.Thread.Sleep(1000); string dataFileVersion = GetFileVersion(dataOutPath); string newDataOutPath = PathUtil.AddVersion2FileName(dataOutPath, dataFileVersion); FileInfo fi = new FileInfo(dataOutPath); fi.MoveTo(newDataOutPath); string configPath = Path.Combine(dataOutFolderPath, "config.txt"); UpdateConfig(configPath, "resVersion", dataFileVersion); DirectoryDelete(outDataFolderPath); //EditorUtility.DisplayDialog("提示", "生成资源增量包成功", "确定"); Debug.Log("生成资源增量包成功"); } else { //EditorUtility.DisplayDialog("提示", "没有可更新的文件", "确定"); Debug.Log("没有可更新的文件"); } AssetDatabase.Refresh(); }