/// <summary> /// 初始化框架编辑器 /// </summary> static public void InitEditorEnvironment() { //是否为batchmode if (Application.isBatchMode) { Debug.Log("BDFramework version:" + BDLauncher.Version); } //只有在非Playing的时候才初始化 if (EditorApplication.isPlayingOrWillChangePlaymode || IsInited) { return; } try { //BD初始化 //BApplication.Init(); //BDEditor初始化 BDEditorApplication.Init(); //加载主工程的DLL Type var assemblyPath = BApplication.Library + "/ScriptAssemblies/Assembly-CSharp.dll"; var editorAssemlyPath = BApplication.Library + "/ScriptAssemblies/Assembly-CSharp-Editor.dll"; if (File.Exists(assemblyPath) && File.Exists(editorAssemlyPath)) { var gAssembly = Assembly.LoadFile(assemblyPath); var eAssemlby = Assembly.LoadFile(editorAssemlyPath); Types = CollectTypes(gAssembly, eAssemlby).ToArray(); } //编辑器下加载初始化 BResources.Init(AssetLoadPathType.Editor); //编辑器下管理器注册 ManagerInstHelper.Load(Types); //Editor的管理器初始化 BDFrameworkPipelineHelper.Init(); //调试器启动 DebuggerServerProcessManager.Inst.Start(); //Pipeline初始化 HotfixPipelineTools.Init(); //编辑器初始化 InitEditorTask(); //编辑器任务 EditorTaskInstance.OnUnityLoadOrCodeRecompiled(); //编辑器http服务 InitEditorHttpServer(); //最后,完成初始化 IsInited = true; // Debug.Log("框架编辑器环境初始化成功!"); } catch (Exception e) { Debug.LogError("框架编辑器环境初始化失败!"); Debug.LogError(e); throw; } }
/// <summary> /// json转sql /// </summary> /// <param name="filePath"></param> /// <param name="jsonContent"></param> static private void Json2Sqlite(string filePath, string jsonContent) { var table = Path.GetFileName(filePath).Replace(Path.GetExtension(filePath), ""); var jsonObj = JsonMapper.ToObject(jsonContent); var dbname = Path.GetFileNameWithoutExtension(SqliteHelper.DB.DBPath); var @namespace = "Game.Data." + dbname + "."; var type = TABLE_TYPES.FirstOrDefault((t) => t.FullName.StartsWith(@namespace) && t.Name.ToLower() == table.ToLower()); if (type == null) { type = TABLE_TYPES.FirstOrDefault((t) => t.FullName.StartsWith("Game.Data.") && t.Name.ToLower() == table.ToLower()); } if (type == null) { Debug.LogError(table + "类不存在,请检查!"); return; } // EditorUtility.DisplayProgressBar("Excel2Sqlite", string.Format("生成:{0} 记录条目:{1}", type.FullName, jsonObj.Count), 1); Debug.LogFormat("导出 [{0}]:{1}", dbname, filePath.Replace(Application.dataPath + "\\", "") + "=>【" + type.FullName + "】"); //数据库创建表 SqliteHelper.DB.CreateTable(type); for (int i = 0; i < jsonObj.Count; i++) { try { var json = jsonObj[i].ToJson(); var jobj = JsonMapper.ToObject(type, json); SqliteHelper.DB.Insert(jobj); } catch (Exception e) { Debug.LogError("导出数据有错,跳过! 错误位置:" + type.Name + ":" + i + "/" + jsonObj.Count + "\n" + e); } } //回调通知 BDFrameworkPipelineHelper.OnExportExcel(type); // EditorUtility.ClearProgressBar(); // EditorUtility.DisplayProgressBar("Excel2Sqlite", string.Format("生成:{0} 记录条目:{1}", type.Name, jsonObj.Count), 1); }
/// <summary> /// 编译模式 /// </summary> /// <param name="outpath"></param> /// <param name="platform"></param> /// <param name="mode"></param> static public void RoslynBuild(string outpath, RuntimePlatform platform, ScriptBuildTools.BuildMode mode, bool isShowTips = true) { //触发bd环境周期 BDFrameworkPipelineHelper.OnBeginBuildHotfixDLL(); var targetPath = "Assets/Code/BDFramework.Game/ILRuntime/Binding/Analysis"; //1.分析之前先删除,然后生成临时文件防止报错 // if (Directory.Exists(targetPath)) // { // Directory.Delete(targetPath, true); // } var fileContent = @" namespace ILRuntime.Runtime.Generated { class CLRBindings { internal static ILRuntime.Runtime.Enviorment.ValueTypeBinder<UnityEngine.Vector2> s_UnityEngine_Vector2_Binding_Binder = null; internal static ILRuntime.Runtime.Enviorment.ValueTypeBinder<UnityEngine.Vector3> s_UnityEngine_Vector3_Binding_Binder = null; internal static ILRuntime.Runtime.Enviorment.ValueTypeBinder<UnityEngine.Vector4> s_UnityEngine_Vector4_Binding_Binder = null; internal static ILRuntime.Runtime.Enviorment.ValueTypeBinder<UnityEngine.Quaternion> s_UnityEngine_Quaternion_Binding_Binder = null; public static void Initialize(ILRuntime.Runtime.Enviorment.AppDomain app) { } } } "; FileHelper.WriteAllText(targetPath + "/CLRBindings.cs", fileContent); AssetDatabase.Refresh(); //这里必须要刷新 //2.生成DLL ScriptBuildTools.BuildDll(outpath, platform, mode, isShowTips); //3.预绑定 //GenPreCLRBinding(); //4.生成自动分析绑定 GenCLRBindingByAnalysis(platform, outpath); //5.拷贝 CopyDLLToOther(outpath, platform); AssetDatabase.Refresh(); //触发bd环境周期 BDFrameworkPipelineHelper.OnEndBuildDLL(outpath); }
/// <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; } //清空表 SqliteHelper.DB.Connection.DropTable <ImportExcelLog>(); { foreach (var f in xlslFiles) { try { Excel2SQLite(f, dbType); } catch (Exception e) { Debug.LogError(e); Debug.LogError("导表失败:" + f); EditorUtility.ClearProgressBar(); } } } SqliteLoder.Close(); // EditorUtility.ClearProgressBar(); //触发bd环境周期 BDFrameworkPipelineHelper.OnEndBuildSqlite(ouptputPath); GlobalAssetsHelper.GenBasePackageAssetBuildInfo(ouptputPath, platform); Debug.Log("导出Sqlite完成!"); }
public override void Build(BuildTarget buildTarget, NodeData nodeData, IEnumerable <PerformGraph.AssetGroups> incoming, IEnumerable <ConnectionData> connectionsToOutput, PerformGraph.Output outputFunc, Action <NodeData, string, float> progressFunc) { #region 保存AssetTypeConfig var asetTypePath = string.Format("{0}/{1}/{2}", BuildingCtx.BuildParams.OutputPath, BApplication.GetPlatformPath(buildTarget), BResources.ART_ASSET_TYPES_PATH); //数据结构保存 AssetTypeConfig at = new AssetTypeConfig() { AssetTypeList = BuildingCtx.AssetTypeList, }; var csv = CsvSerializer.SerializeToString(at); FileHelper.WriteAllText(asetTypePath, csv); Debug.LogFormat("AssetType写入到:{0} \n{1}", asetTypePath, csv); #endregion //BD生命周期触发 BDFrameworkPipelineHelper.OnBeginBuildAssetBundle(BuildingCtx); }
/// <summary> /// 构建包体,使用当前配置、资源 /// </summary> static public bool BuildIpa(BuildMode buildMode, bool isGenAssets, string outdir) { bool ret = false; //增加平台路径 outdir = IPath.Combine(outdir, BApplication.GetPlatformPath(BuildTarget.iOS)); BDFrameworkPipelineHelper.OnBeginBuildPackage(BuildTarget.iOS, outdir); //0.加载场景和配置 LoadConfig(buildMode); //1.生成资源 if (isGenAssets) { BuildAssetsTools.BuildAllAssets(RuntimePlatform.IPhonePlayer, BApplication.DevOpsPublishAssetsPath); } //2.拷贝资源打包 AssetDatabase.StartAssetEditing(); //停止触发资源导入 { //拷贝资源 DevOpsTools.CopyPublishAssetsTo(Application.streamingAssetsPath, RuntimePlatform.IPhonePlayer); try { var(_ret, outputpath) = BuildIpa(buildMode, outdir); BDFrameworkPipelineHelper.OnEndBuildPackage(BuildTarget.iOS, outputpath); ret = _ret; } catch (Exception e) { //For ci throw e; } DevOpsTools.DeleteCopyAssets(Application.streamingAssetsPath, RuntimePlatform.IPhonePlayer); } AssetDatabase.StopAssetEditing(); //恢复触发资源导入 return(ret); }
/// <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 = GlobalAssetsHelper.GetPackageBuildInfo(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.生成母包资源信息 GlobalAssetsHelper.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> /// 开始构建AB /// </summary> public void StartBuildAssetBundle(BuildTarget buildTarget) { //-----------------------开始打包AssetBundle逻辑--------------------------- Debug.Log("【BuildAssetbundle】执行Build..."); //设置编辑器状态 BDEditorApplication.EditorStatus = BDFrameworkEditorStatus.BuildAssetBundle; var platform = BApplication.GetRuntimePlatform(buildTarget); var platformOutputPath = IPath.Combine(BuildParams.OutputPath, BApplication.GetPlatformPath(platform)); string abOutputPath = IPath.Combine(platformOutputPath, BResources.ART_ASSET_ROOT_PATH); //--------------------------------开始打包---------------------------------- //1.打包 Debug.Log("<color=green>----->1.进入打包逻辑</color>"); //整理abname this.MergeABName(BuildingAssetInfos); //对比差异文件 var changedAssetsInfo = GetChangedAssets(BuildingAssetInfos, buildTarget); //生成artconfig var assetbundleItemList = this.GenAssetBundleConfig(BuildingAssetInfos, BuildParams, platform); //打包 AssetDatabase.StartAssetEditing(); //禁止自动导入 { this.BuildAssetBundle(assetbundleItemList, changedAssetsInfo, BuildParams, platform); } AssetDatabase.StopAssetEditing(); //恢复自动导入 //2.清理 Debug.Log("<color=green>----->2.清理旧ab</color>"); //移除所有的ab RemoveAllAssetbundleName(); //删除本地没有的资源 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.BuildInfo配置处理 Debug.Log("<color=green>----->3.BuildInfo相关生成</color>"); //设置ab的hash foreach (var abi in assetbundleItemList) { if (string.IsNullOrEmpty(abi.AssetBundlePath)) { continue; } var abpath = IPath.Combine(platformOutputPath, BResources.ART_ASSET_ROOT_PATH, abi.AssetBundlePath); var hash = FileHelper.GetMurmurHash3(abpath); abi.Hash = hash; } //获取上一次打包的数据,跟这次打包数据合并 var configPath = IPath.Combine(platformOutputPath, BResources.ART_ASSET_CONFIG_PATH); if (File.Exists(configPath)) { var lastAssetbundleItemList = CsvSerializer.DeserializeFromString <List <AssetBundleItem> >(File.ReadAllText(configPath)); foreach (var newABI in assetbundleItemList) { if (string.IsNullOrEmpty(newABI.AssetBundlePath)) { continue; } // //判断是否在当前打包列表中 // var ret = changedAssetsInfo.AssetDataMaps.Values.FirstOrDefault((a) => a.ABName.Equals(newABI.AssetBundlePath, StringComparison.OrdinalIgnoreCase)); var lastABI = lastAssetbundleItemList.FirstOrDefault((last) => newABI.AssetBundlePath.Equals(last.AssetBundlePath, StringComparison.OrdinalIgnoreCase)); //AB名相等 //&& newABI.Hash == last.Hash); //hash相等 //没重新打包,则用上一次的mix信息 if (lastABI != null && lastABI.Hash == newABI.Hash) { newABI.Mix = lastABI.Mix; } //否则mix = 0 } } //保存artconfig.info var csv = CsvSerializer.SerializeToString(assetbundleItemList); FileHelper.WriteAllText(configPath, csv); //保存BuildInfo配置 var buildinfoPath = IPath.Combine(platformOutputPath, BResources.EDITOR_ART_ASSET_BUILD_INFO_PATH); //缓存buildinfo var json = JsonMapper.ToJson(BuildingAssetInfos, true); FileHelper.WriteAllText(buildinfoPath, json); //4.备份Artifacts //this.BackupArtifacts(buildTarget); //5.检测本地的Manifest和构建预期对比 Debug.Log("<color=green>----->5.校验AB依赖</color>"); var abRootPath = IPath.Combine(BuildParams.OutputPath, BApplication.GetPlatformPath(platform), BResources.ART_ASSET_ROOT_PATH); var previewABUnitMap = BuildingAssetInfos.PreviewAssetbundleUnit(); var manifestList = Directory.GetFiles(abRootPath, "*.manifest", SearchOption.AllDirectories); //解析 manifestBuildParams.OutputPath for (int i = 0; i < manifestList.Length; i++) { var manifest = manifestList[i].Replace("\\", "/"); if (manifest.Equals(abRootPath + ".manifest")) { continue; } var lines = File.ReadLines(manifest); List <string> manifestDependList = new List <string>(); bool isStartRead = false; foreach (var line in lines) { if (!isStartRead && line.Equals("Assets:")) { isStartRead = true; } else if (line.Contains("Dependencies:")) { break; } else if (isStartRead) { var file = line.Replace("- ", ""); manifestDependList.Add(file.ToLower()); } } //对比依赖 var abname = Path.GetFileNameWithoutExtension(manifest); if (abname.Equals(BResources.ART_ASSET_ROOT_PATH, StringComparison.OrdinalIgnoreCase)) { continue; } previewABUnitMap.TryGetValue(abname, out var previewABDependList); if (previewABDependList == null) { Debug.LogError("【AssetbundleV2-验证】本地ab的配置不不存在:" + abname); Debug.LogError("path:" + AssetDatabase.GUIDToAssetPath(abname)); } else { //求差集 var except = manifestDependList.Except(previewABDependList); if (except.Count() != 0) { var local = JsonMapper.ToJson(manifestDependList, true); var preview = JsonMapper.ToJson(previewABDependList, true); Debug.LogError($"【AssetbundleV2-验证】本地AssetBundle依赖与预期不符:\n 本地:{local} \n 预期:{preview}"); } } } //6.资源混淆 Debug.Log("<color=green>----->6.混淆AB</color>"); if (BDEditorApplication.BDFrameworkEditorSetting.BuildAssetBundleSetting.IsEnableObfuscation) { AssetBundleEditorToolsV2.MixAssetBundle(BuildParams.OutputPath, platform); } //恢复编辑器状态 BDEditorApplication.EditorStatus = BDFrameworkEditorStatus.Idle; //BD生命周期触发 BDFrameworkPipelineHelper.OnEndBuildAssetBundle(this); //GenAssetBundleItemCacheList = abConfigList.ToList(); }