/// <summary> /// 读取游戏版本号 /// </summary> private void readGameVersion() { // 拷贝资源版本号 #if UNITY_IOS string destVersionPath = BuilderPreference.VERSION_PATH + "/version_ios.txt"; #else string destVersionPath = BuilderPreference.VERSION_PATH + "/version.txt"; #endif if (!File.Exists(destVersionPath)) { destVersionPath = BuilderPreference.ASSET_PATH + "/version.txt"; } if (File.Exists(destVersionPath)) { var versionPath = BuilderPreference.BUILD_PATH + "/version.txt"; BuildUtil.SwapPathDirectory(versionPath); File.Copy(destVersionPath, versionPath, true); gameVersion = GameVersion.CreateVersion(File.ReadAllText(versionPath)); } else { gameVersion = GameVersion.CreateVersion(Application.version); } // 读取游戏版本号 apkVersion = 0; destVersionPath = BuilderPreference.VERSION_PATH + "/apk_version.txt"; if (File.Exists(destVersionPath)) { var ver = File.ReadAllText(destVersionPath); apkVersion = Convert.ToInt32(ver); } }
private void CopyLuaBytesFiles(string sourceDir, string destDir) { if (!Directory.Exists(sourceDir)) { return; } string[] files = Directory.GetFiles(sourceDir, "*.lua", SearchOption.AllDirectories); for (int i = 0; i < files.Length; i++) { string dest = files[i].Replace(sourceDir, destDir) + ".bytes"; BuildUtil.SwapPathDirectory(dest); if (AppConst.LuaByteMode) { EncodeLuaFile(files[i], dest); } else { var srcFile = files[i]; srcFile = RemoveLogInLua(srcFile, dest); File.Copy(srcFile, dest, true); } } }
/// <summary> /// 建立ab映射文件 /// </summary> private void BuildBundleNameMapFile() { if (Builder.AssetMaps == null) { return; } string savePath = BuilderPreference.BUILD_PATH + "/bundlemap.ab"; StringBuilder sb = new StringBuilder(); foreach (AssetMap asset in Builder.AssetMaps.Values) { if (!asset.IsBinding) { continue; } int rootLength = 0; foreach (string rootFolder in BuilderPreference.BundleMapFile) { if (asset.AssetPath.StartsWith(rootFolder)) { rootLength = rootFolder.Length; break; } } if (rootLength <= 0) { continue; } string assetName = asset.AssetPath.Substring(rootLength + 1); if (asset.Rule.FileFilterType == FileType.Scene) { assetName = Path.GetFileName(asset.AssetPath); } string abName = BuildUtil.FormatBundleName(asset.Rule); int preload = asset.Rule.LoadType == ELoadType.PreLoad ? 1 : 0; string str = string.Format("{0}|{1}.{2}|{3}", assetName.Split('.')[0].ToLower(), abName, BuilderPreference.VARIANT_V1, preload); sb.AppendLine(str); } if (File.Exists(savePath)) { File.Delete(savePath); } BuildUtil.SwapPathDirectory(savePath); File.WriteAllBytes(savePath, Crypto.Encode(Riverlake.Encoding.GetBytes(sb.ToString()))); Builder.AddBuildLog("<Asset Config Building> Gen bundle name map file !"); }
/// <summary> /// 保存写入游戏版本数据 /// </summary> public void SaveVersion() { string resVersion = gameVersion.ToString(); #if UNITY_IOS string resVersionPath = BuilderPreference.VERSION_PATH + "/version_ios.txt"; #else string resVersionPath = BuilderPreference.VERSION_PATH + "/version.txt"; #endif BuildUtil.SwapPathDirectory(resVersionPath); File.WriteAllText(resVersionPath, resVersion.ToString()); }
public void CopyAssets(string fromPath) { string toPath = BuilderPreference.ASSET_PATH; if (Directory.Exists(toPath)) { Directory.Delete(toPath, true); } Directory.CreateDirectory(toPath); var dirInfo = new DirectoryInfo(fromPath); Builder.AddBuildLog("<Compress Building> Copying assets..."); int index = 0; FileInfo[] files = dirInfo.GetFiles("*.*", SearchOption.AllDirectories); List <string[]> comprssFiles = new List <string[]>(); foreach (var file in files) { index++; // ShowProgress("Copying assets...", (float)index / (float)files.Length); if (file.Name.EndsWith(".meta") || file.Name.EndsWith(".manifest") || file.Name.Contains("config.txt")) { continue; } string relativePath = BuildUtil.RelativePaths(file.FullName); string to = relativePath.Replace(fromPath, toPath); BuildUtil.SwapPathDirectory(to); if (relativePath.EndsWith(".ab")) { comprssFiles.Add(new [] { relativePath, to }); } else { File.Copy(relativePath, to, true); } } totalCompressCount = comprssFiles.Count; compressIndex = 0; for (int i = 0; i < comprssFiles.Count; i++) { ThreadPool.QueueUserWorkItem(onThreadCompress, comprssFiles[i]); } }
public void CopyToAssetBundle() { Builder.AddBuildLog("<Assetbundle Building> Copying to AssetBundle folder..."); string fromPath = BuilderPreference.TEMP_ASSET_PATH; string toPath = BuilderPreference.BUILD_PATH; if (Directory.Exists(toPath)) { Directory.Delete(toPath, true); } Directory.CreateDirectory(toPath); var dirInfo = new DirectoryInfo(fromPath); if (dirInfo.Exists) { int index = 0; FileInfo[] files = dirInfo.GetFiles("*.*", SearchOption.AllDirectories); foreach (var file in files) { index++; if (file.Name.Contains("config.txt")) { continue; } string relativePath = file.FullName.Replace("\\", "/"); string to = relativePath.Replace(fromPath, toPath); BuildUtil.SwapPathDirectory(to); File.Copy(relativePath, to, true); } } Builder.AddBuildLog("<Assetbundle Building> Copying to AssetBundle folder end ..."); }
private void CopyAllBundles() { string targetPath = BuilderPreference.StreamingAssetsPlatormPath; if (Directory.Exists(targetPath)) { Directory.Delete(targetPath, true); } Directory.CreateDirectory(targetPath); string buildPath = BuilderPreference.BUILD_PATH; HashSet <string> withExtensions = new HashSet <string>() { ".ab", ".unity3d", ".txt", ".conf", ".pb", ".bytes" }; List <string> files = BuildUtil.SearchIncludeFiles(buildPath, SearchOption.AllDirectories, withExtensions); Builder.AddBuildLog("<FullPackage Building> Copy all bundle ..."); // int buildPathLength = buildPath.Length + 1; for (int i = 0; i < files.Count; ++i) { string fileName = Path.GetFileName(files[i]); if (fileName == "tempsizefile.txt" || fileName == "luamd5.txt") { continue; } //ABPackHelper.ShowProgress("Copying files...", (float)i / (float)files.Length); string streamBundlePath = files[i].Replace(buildPath, targetPath); BuildUtil.SwapPathDirectory(streamBundlePath); File.Copy(files[i], streamBundlePath); } AssetDatabase.Refresh(); // ABPackHelper.ShowProgress("", 1); }
/// <summary> /// 拷贝协议文件 /// </summary> private void CopyHandleBundle() { string bundleLuaPath = string.Concat(BuilderPreference.BUILD_PATH, "/lua/"); for (int i = 0; i < luaPaths.Length; i++) { if (!Directory.Exists(luaPaths[i])) { continue; } string luaDataPath = luaPaths[i].ToLower(); List <string> includeFiles = BuildUtil.SearchFiles(luaDataPath, SearchOption.AllDirectories); //拷贝protocol foreach (string f in includeFiles) { if (f.EndsWith(".lua")) { continue; } var cmpStr = f.ToLower(); if (cmpStr.Contains("protocol/")) { string newPath = f.Replace(luaDataPath, bundleLuaPath); BuildUtil.SwapPathDirectory(newPath); File.Copy(f, newPath, true); } } } Builder.AddBuildLog("<Lua Building> copy lua handle bundles "); }
public void CopyToTempAssets() { string fromPath = BuilderPreference.BUILD_PATH; string toPath = BuilderPreference.TEMP_ASSET_PATH; if (Directory.Exists(toPath)) { Directory.Delete(toPath, true); } Directory.CreateDirectory(toPath); var dirInfo = new DirectoryInfo(fromPath); Builder.AddBuildLog("<Compress Building> Copying to temp assets..."); int index = 0; FileInfo[] files = dirInfo.GetFiles("*.*", SearchOption.AllDirectories); foreach (var file in files) { index++; // ShowProgress("Copying to temp assets...", (float)index / (float)files.Length); if (file.Name.EndsWith(".meta") || file.Name.Contains("config.txt")) { continue; } string relativePath = BuildUtil.RelativePaths(file.FullName); string to = relativePath.Replace(fromPath, toPath); BuildUtil.SwapPathDirectory(to); File.Copy(relativePath, to, true); } // ShowProgress("", 1); }
protected string BuildApp(bool packAllRes, bool forceUpdate) { Builder.AddBuildLog("Build App Start !... packAllRes:" + packAllRes + ",force update:" + forceUpdate); var option = BuildOptions.None; if (Builder.IsDebug) { option |= BuildOptions.AllowDebugging; } if (Builder.IsBuildDev) { option |= BuildOptions.Development; } if (Builder.IsAutoConnectProfile) { option |= BuildOptions.ConnectWithProfiler; } string dir = Path.GetDirectoryName(Builder.ApkSavePath); string fileName = Path.GetFileNameWithoutExtension(Builder.ApkSavePath); string time = DateTime.Now.ToString("yyyyMMdd"); string flag = string.Empty; BuildTarget buildTarget = EditorUserBuildSettings.activeBuildTarget; string final_path = string.Empty; if (buildTarget != BuildTarget.iOS) { SDKConfig curSdkConfig = Builder.CurrentConfigSDK; for (int i = 0; i < curSdkConfig.items.Count; i++) { var item = Builder.CurrentConfigSDK.items[i]; BuildOptions targetOptions = option; if (item.development == 1) { targetOptions |= BuildOptions.Development; flag = packAllRes ? "_allpack_dev_v" : "_subpack_dev_v"; } else if (item.use_sdk == 1) { flag = packAllRes ? "_allpack_sdk_v" : "_subpack_sdk_v"; } else { flag = packAllRes ? "_allpack_test_v" : "_subpack_test_v"; } if (buildTarget == BuildTarget.Android) { final_path = string.Concat(dir, "/", fileName, "_", time, flag, Builder.GameVersion.ToString(), ".apk"); if (File.Exists(final_path)) { File.Delete(final_path); } // 写入并保存sdk启用配置 // item.CopyConfig(); // item.CopySDK(); // item.SetPlayerSetting(curSdkConfig.splash_image); // item.SaveSDKConfig(); //item.SplitAssets(sdkConfig.split_assets); if (item.update_along == 0 && forceUpdate) { if (Directory.Exists(Application.streamingAssetsPath)) { Directory.Delete(Application.streamingAssetsPath, true); } } } else if (buildTarget == BuildTarget.StandaloneWindows64 || buildTarget == BuildTarget.StandaloneWindows) { final_path = string.Concat(dir, "/", fileName, "_", time, flag, Builder.GameVersion.ToString(), ".exe"); if (Directory.Exists(final_path)) { Directory.Delete(final_path, true); } item.CopyConfig(); } AssetDatabase.Refresh(); BuildUtil.SwapPathDirectory(final_path); BuildPipeline.BuildPlayer(GetBuildScenes(), final_path, buildTarget, targetOptions); item.ClearSDK(); } } else if (buildTarget == BuildTarget.iOS) { // 在上传目录新建一个ios_check.txt文件用于判断当前包是否出于提审状态 string checkFile = BuilderPreference.ASSET_PATH + "/ios_check.txt"; if (File.Exists(checkFile)) { File.Delete(checkFile); } File.WriteAllText(checkFile, "1"); XCConfigItem configItem = XCConfigItem.ParseXCConfig(XCodePostProcess.config_path); if (configItem != null) { PlayerSettings.applicationIdentifier = configItem.bundleIdentifier; PlayerSettings.productName = configItem.product_name; configItem.CopyConfig(); } // IOSGenerateHelper.IOSConfusing(); AssetDatabase.Refresh(); BuildPipeline.BuildPlayer(GetBuildScenes(), Builder.ApkSavePath, buildTarget, option); } Resources.UnloadUnusedAssets(); GC.Collect(); Builder.AddBuildLog("[end]Build App Finish !..."); return(final_path); }
/// <summary> /// 复制分包资源到StreamingAssets目录下 /// </summary> void CopyPackableFiles() { string targetPath = BuilderPreference.StreamingAssetsPlatormPath; if (Directory.Exists(targetPath)) { Directory.Delete(targetPath, true); } Directory.CreateDirectory(targetPath); string bundlePath = BuilderPreference.BUILD_PATH; //拷贝StreamAsset目录中的资源 AssetBuildRule[] rules = AssetBuildRuleManager.Instance.Rules; Dictionary <string, AssetBuildRule> ruleMap = new Dictionary <string, AssetBuildRule>(); for (int i = 0; i < rules.Length; i++) { List <AssetBuildRule> ruleList = rules[i].TreeToList(); for (int j = 0; j < ruleList.Count; j++) { ruleMap[ruleList[j].AssetBundleName] = ruleList[j]; } } //只拷贝整包类型的文件 foreach (AssetBuildRule bundleRule in ruleMap.Values) { if (bundleRule.PackageType != PackageAssetType.InPackage) { continue; } string assetBundleName = BuildUtil.FormatBundleName(bundleRule); string buildBundlePath = string.Concat(bundlePath, "/", assetBundleName, BuilderPreference.VARIANT_V1); if (!File.Exists(buildBundlePath)) { continue; } string streamBundlePath = string.Concat(targetPath, "/", assetBundleName, BuilderPreference.VARIANT_V1); BuildUtil.SwapPathDirectory(streamBundlePath); File.Copy(buildBundlePath, streamBundlePath); } Action <List <string>, string> copyFiles = (filePaths, rootPath) => { for (int i = 0; i < filePaths.Count; i++) { string relativePath = filePaths[i]; if (!File.Exists(relativePath)) { continue; } string streamBundlePath = relativePath.Replace(rootPath, targetPath); BuildUtil.SwapPathDirectory(streamBundlePath); File.Copy(relativePath, streamBundlePath); } }; HashSet <string> includeExtensions = new HashSet <string>() { ".ab", ".unity3d", ".txt", ".conf", ".pb", ".bytes" }; //拷贝bundle配置目录的配置文件 string[] copyTargetPaths = new[] { string.Concat(bundlePath, "/files.txt"), string.Concat(bundlePath, "/bundlemap.ab"), string.Concat(bundlePath, "/font.ab"), string.Concat(bundlePath, "/shader.ab"), }; List <string> files = new List <string>(copyTargetPaths); copyFiles(files, bundlePath); //拷贝Lua目录代码 string luaBundlePath = string.Concat(bundlePath, "/lua"); files = BuildUtil.SearchIncludeFiles(luaBundlePath, SearchOption.AllDirectories, includeExtensions); copyFiles(files, luaBundlePath); Builder.AddBuildLog("<Sub Package Building>Copy sub package files ..."); AssetDatabase.Refresh(); }
private void BuildFileIndex() { Builder.AddBuildLog("<Asset Config Building> start Build File Index ...."); string resPath = BuilderPreference.BUILD_PATH + "/"; //----------------------创建文件列表----------------------- string newFilePath = resPath + "files.txt"; if (File.Exists(newFilePath)) { File.Delete(newFilePath); } string tempSizeFile = resPath + "tempsizefile.txt"; Dictionary <string, string> assetTypeDict = new Dictionary <string, string>(); if (File.Exists(tempSizeFile)) { var sizeFileContent = File.ReadAllText(tempSizeFile); var temps = sizeFileContent.Split('\n'); for (int i = 0; i < temps.Length; ++i) { if (!string.IsNullOrEmpty(temps[i])) { var temp = temps[i].Split('|'); if (temp.Length != 2 && temp.Length != 3) { throw new System.IndexOutOfRangeException(); } var assetType = temp[1]; if (temp.Length == 3) { assetType += "|" + temp[2]; } assetTypeDict.Add(temp[0], assetType); //UpdateProgress(i, temps.Length, temps[i]); } } // EditorUtility.ClearProgressBar(); } List <string> includeFiles = BuildUtil.SearchFiles(resPath, SearchOption.AllDirectories); HashSet <string> excludeSuffxs = new HashSet <string>() { ".DS_Store", ".manifest" }; //排除文件 BuildUtil.SwapPathDirectory(newFilePath); using (FileStream fs = new FileStream(newFilePath, FileMode.CreateNew)) { StreamWriter sw = new StreamWriter(fs); for (int i = 0; i < includeFiles.Count; i++) { string file = includeFiles[i]; string ext = Path.GetExtension(file); if (excludeSuffxs.Contains(ext) || file.EndsWith("apk_version.txt") || file.Contains("tempsizefile.txt") || file.Contains("luamd5.txt")) { continue; } string md5 = MD5.ComputeHashString(file); int size = (int)new FileInfo(file).Length; string value = file.Replace(resPath, string.Empty).ToLower(); if (assetTypeDict.ContainsKey(value)) { sw.WriteLine("{0}|{1}|{2}|{3}", value, md5, size, assetTypeDict[value]); } else { sw.WriteLine("{0}|{1}|{2}", value, md5, size); } // UpdateProgress(i, includeFiles.Count, file); } sw.Close(); } // EditorUtility.ClearProgressBar(); Builder.AddBuildLog("<Asset Config Building> Build File Index end ...."); }