/// <summary> /// 生成sqlite /// 默认导出到当前平台目录下 /// </summary> /// <param name="ouptputPath">自定义路径</param> public static void AllExcel2SQLite(string ouptputPath, RuntimePlatform platform, DBType dbType = DBType.Local) { //触发bd环境周期 BDFrameworkPipelineHelper.OnBeginBuildSqlite(); var xlslFiles = ExcelEditorTools.GetAllExcelFiles(); switch (dbType) { case DBType.Local: SqliteLoder.LoadLocalDBOnEditor(ouptputPath, platform); break; case DBType.Server: SqliteLoder.LoadServerDBOnEditor(ouptputPath, platform); break; } { foreach (var f in xlslFiles) { try { Excel2SQLite(f, dbType); } catch (Exception e) { Debug.LogError("导表失败:" + f); EditorUtility.ClearProgressBar(); } } } SqliteLoder.Close(); // EditorUtility.ClearProgressBar(); //触发bd环境周期 BDFrameworkPipelineHelper.OnEndBuildSqlite(ouptputPath); BasePackageAssetsHelper.GenBasePackageAssetBuildInfo(ouptputPath, platform); Debug.Log("导出Sqlite完成!"); }
/// <summary> /// 编译DLL /// </summary> static public void BuildDll(string outPath, RuntimePlatform platform, BuildMode mode, bool isShowTips = true) { IsShowTips = isShowTips; if (IsShowTips) { EditorUtility.DisplayProgressBar("编译服务", "准备编译环境...", 0.1f); } try { //生成CSProj EditorApplication.ExecuteMenuItem("Assets/Open C# Project"); } catch { } //准备输出环境 var _outPath = Path.Combine(outPath, BApplication.GetPlatformPath(platform)); try { var path = _outPath + "/Hotfix"; if (Directory.Exists(path)) { Directory.Delete(path, true); } Directory.CreateDirectory(path); } catch (Exception e) { Debug.LogError(e.Message); if (IsShowTips) { EditorUtility.ClearProgressBar(); EditorUtility.DisplayDialog("提示", "请手动删除hotfix文件后重试!", "OK"); } return; } if (IsShowTips) { EditorUtility.DisplayProgressBar("编译服务", "开始处理脚本", 0.2f); } #region CS DLL引用搜集处理 List <string> dllFileList = new List <string>(); List <string> csFileList = new List <string>(); //所有宏 defineList = new List <string>(); string[] parseCsprojList = new string[] { "Assembly-CSharp.csproj", "BDFramework.Core.csproj" }; foreach (var csproj in parseCsprojList) { var path = Path.Combine(BApplication.ProjectRoot, csproj); if (!File.Exists(path)) { EditorUtility.DisplayDialog("警告", $"请保证csproj存在:\n {csproj}.\n 请在Preferces/ExternalTools 选择 Generate.csproj文件", "OK"); return; } ParseCsprojFile(path, new List <string>() { }, ref csFileList, ref dllFileList); } //去重 dllFileList = dllFileList.Distinct().ToList(); csFileList = csFileList.Distinct().ToList(); defineList = defineList.Distinct().ToList(); //移除参与分析csproj的dll,因为已经解析 包含在cs foreach (var csproj in parseCsprojList) { var dll = csproj.Replace(".csproj", ".dll"); var idx = dllFileList.FindIndex((d) => d.EndsWith(dll, StringComparison.OrdinalIgnoreCase)); if (idx >= 0) { dllFileList.RemoveAt(idx); //Debug.Log("[Build DLL]剔除:" + dll); } } //宏解析 //移除editor相关宏 for (int i = defineList.Count - 1; i >= 0; i--) { var symbol = defineList[i]; if (symbol.Contains("UNITY_EDITOR")) { defineList.RemoveAt(i); } } //剔除不存的dll //TODO 这里是File 接口mac下有bug 会判断文件不存在 if (Application.platform == RuntimePlatform.WindowsEditor || Application.platform == RuntimePlatform.OSXEditor) { for (int i = dllFileList.Count - 1; i >= 0; i--) { var dll = dllFileList[i]; if (!File.Exists(dll)) { dllFileList.RemoveAt(i); Debug.Log("剔除:" + dll); } } } #endregion // 热更代码 = 框架部分@hotfix + 游戏逻辑部分@hotfix var baseCs = csFileList.FindAll(f => !f.Contains(STR_HOTFIX) && f.EndsWith(".cs")); //筛选cs //不用ILR binding进行编译base.dll,因为binding本身会因为@hotfix调整容易报错 baseCs = baseCs.Where((cs) => (!cs.Contains("\\ILRuntime\\Binding\\Analysis\\") && !cs.Contains("/ILRuntime/Binding/Analysis/")) || cs.EndsWith("CLRBindings.cs")).ToList(); // var hotfixCs = csFileList.FindAll(f => (f.Contains(STR_HOTFIX) || f.Contains(STR_HALF_HOTFIX)) && f.EndsWith(".cs")); var outHotfixPath = Path.Combine(_outPath, DLLPATH); if (mode == BuildMode.Release) { Build(baseCs, hotfixCs, dllFileList, outHotfixPath); } else if (mode == BuildMode.Debug) { Build(baseCs, hotfixCs, dllFileList, outHotfixPath, true); } BasePackageAssetsHelper.GenBasePackageAssetBuildInfo(outPath, platform); }
/// <summary> /// 构建所有资源 /// </summary> /// <param name="platform">平台</param> /// <param name="outputPath">输出目录</param> /// <param name="setNewVersionNum">新版本号</param> static public void BuildAllAssets(RuntimePlatform platform, string outputPath, string setNewVersionNum = null) { var newVersionNum = ""; //触发事件 var lastPackageBuildInfo = BasePackageAssetsHelper.GetPacakgeBuildInfo(outputPath, platform); var lastVersionNum = lastPackageBuildInfo.Version; //没有指定版本号,则需要触发版本号的实现逻辑 if (string.IsNullOrEmpty(setNewVersionNum)) { BDFrameworkPipelineHelper.OnBeginBuildAllAssets(platform, outputPath, lastVersionNum, out newVersionNum); } //项目没有实现提供新的版本号,则内部提供一个版本号 if (string.IsNullOrEmpty(newVersionNum) || lastVersionNum == newVersionNum) { //没指定版本号 if (string.IsNullOrEmpty(setNewVersionNum)) { newVersionNum = VersionNumHelper.AddVersionNum(lastVersionNum, add: 1); } //指定版本号 else { newVersionNum = VersionNumHelper.AddVersionNum(lastVersionNum, setNewVersionNum); } } //开始构建资源 var _outputPath = Path.Combine(outputPath, BApplication.GetPlatformPath(platform)); if (!Directory.Exists(_outputPath)) { Directory.CreateDirectory(_outputPath); } //1.编译脚本 try { EditorWindow_ScriptBuildDll.RoslynBuild(outputPath, platform, ScriptBuildTools.BuildMode.Release); } catch (Exception e) { Debug.LogError(e.Message); } //2.打包表格 try { Excel2SQLiteTools.AllExcel2SQLite(outputPath, platform); } catch (Exception e) { Debug.LogError(e.Message); } //3.打包资源 try { //var config = BDEditorApplication.BDFrameWorkFrameEditorSetting.BuildAssetBundle; AssetBundleEditorToolsV2.GenAssetBundle(outputPath, platform); } catch (Exception e) { Debug.LogError(e.Message); } //4.生成母包资源信息 BasePackageAssetsHelper.GenBasePackageAssetBuildInfo(outputPath, platform, version: newVersionNum); //5.生成本地Assets.info配置 //这个必须最后生成!!!! //这个必须最后生成!!!! //这个必须最后生成!!!! var allServerAssetItemList = PublishPipelineTools.GetAssetItemList(outputPath, platform); var csv = CsvSerializer.SerializeToString(allServerAssetItemList); var assetsInfoPath = BResources.GetAssetsInfoPath(outputPath, platform); FileHelper.WriteAllText(assetsInfoPath, csv); // Debug.Log($"<color=yellow>{ BApplication.GetPlatformPath(platform)} - 旧版本:{lastPackageBuildInfo.Version} 新版本号:{newVersionNum} </color> "); //完成回调通知 BDFrameworkPipelineHelper.OnEndBuildAllAssets(platform, outputPath, newVersionNum); }
/// <summary> /// 打包Asset Bundle /// </summary> /// <param name="buildAssetsInfo"></param> /// <param name="buildParams"></param> /// <param name="platform"></param> private void BuildAssetBundle(List <AssetBundleItem> assetBundleItemList, BuildAssetsInfo buildAssetsInfo, BuildAssetBundleParams buildParams, RuntimePlatform platform) { //----------------------------开始设置build ab name------------------------------- //根据传进来的资源,设置AB name foreach (var buildInfoItem in buildAssetsInfo.AssetDataMaps) { var assetPath = buildInfoItem.Key; var assetData = buildInfoItem.Value; //设置ab name var ai = GetAssetImporter(assetPath); if (ai) { ai.SetAssetBundleNameAndVariant(assetData.ABName, null); } } //----------------------------生成AssetBundle------------------------------- var platformOutputPath = Path.Combine(buildParams.OutputPath, BApplication.GetPlatformPath(platform)); string abOutputPath = IPath.Combine(platformOutputPath, BResources.ART_ASSET_ROOT_PATH); if (!Directory.Exists(abOutputPath)) { Directory.CreateDirectory(abOutputPath); } //配置 var buildTarget = BApplication.GetBuildTarget(platform); BuildAssetBundleOptions buildOpa = BuildAssetBundleOptions.ChunkBasedCompression | //压缩 BuildAssetBundleOptions.DeterministicAssetBundle | //保证一致 //BuildAssetBundleOptions.DisableWriteTypeTree| //关闭TypeTree BuildAssetBundleOptions.DisableLoadAssetByFileName | BuildAssetBundleOptions.DisableLoadAssetByFileNameWithExtension; //关闭使用filename加载 //关闭TypeTree var buildAssetConf = BDEditorApplication.BDFrameWorkFrameEditorSetting?.BuildAssetBundle; if (buildAssetConf.IsDisableTypeTree) { buildOpa |= BuildAssetBundleOptions.DisableWriteTypeTree; //关闭TypeTree } UnityEditor.BuildPipeline.BuildAssetBundles(abOutputPath, buildOpa, buildTarget); Debug.LogFormat("【编译AssetBundle】 output:{0} ,buildTarget:{1}", abOutputPath, buildTarget.ToString()); //----------------------------清理------------------------------------- //1.移除所有的ab RemoveAllAssetbundleName(); //2.删除本地没有的资源 var allABList = Directory.GetFiles(abOutputPath, "*", SearchOption.AllDirectories).Where((p) => string.IsNullOrEmpty(Path.GetExtension(p))); foreach (var abpath in allABList) { var abname = Path.GetFileName(abpath); var ret = assetBundleItemList.FirstOrDefault((abdata) => abdata.AssetBundlePath == abname); if (ret == null) { // File.Delete(abpath); File.Delete(abpath + ".manifest"); // var path = AssetDatabase.GUIDToAssetPath(abname); Debug.Log("【删除旧ab:】" + abname + " - " + path); } } //3.检测本地Assetbundle // allAbList = Directory.GetFiles(abOutputPath, "*", SearchOption.AllDirectories); // foreach (var abpath in allAbList) // { // if (abpath.Contains(".")) // { // continue; // } // // var depend = AssetDatabase.GetAssetBundleDependencies(abpath,true); // } BasePackageAssetsHelper.GenBasePackageAssetBuildInfo(buildParams.OutputPath, platform); }