/// <summary> /// 生成sqlite /// 默认导出到当前平台目录下 /// </summary> /// <param name="ouptputPath">自定义路径</param> public static void ALLExcel2SQLite(string ouptputPath, RuntimePlatform platform) { //触发bd环境周期 BDFrameEditorBehaviorHelper.OnBeginBuildSqlite(); var xlslFiles = GetAllConfigFiles(); SqliteLoder.LoadOnEditor(ouptputPath, platform); { foreach (var f in xlslFiles) { try { Excel2SQLite(f); } catch (Exception e) { Debug.LogError("导表失败:" + f); } } } SqliteLoder.Close(); // EditorUtility.ClearProgressBar(); //触发bd环境周期 BDFrameEditorBehaviorHelper.OnEndBuildSqlite(ouptputPath); AssetHelper.AssetHelper.GenPackageBuildInfo(ouptputPath, platform); Debug.Log("导出Sqlite完成!"); }
/// <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环境周期 BDFrameEditorBehaviorHelper.OnBeginBuildDLL(); 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); AssetDatabase.Refresh(); //触发bd环境周期 BDFrameEditorBehaviorHelper.OnEndBuildDLL(outpath); }
/// <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) { //触发bd环境周期 BDFrameEditorBehaviorHelper.OnBeginBuildDLL(); var targetPath = "Assets/Code/Game/ILRuntime/Binding/Analysis"; //1.分析之前先删除,然后生成临时文件防止报错 if (Directory.Exists(targetPath)) { Directory.Delete(targetPath, true); } var fileContent = @" namespace ILRuntime.Runtime.Generated { class CLRBindings { public static void Initialize(ILRuntime.Runtime.Enviorment.AppDomain app) { } } } "; FileHelper.WriteAllText(targetPath + "/CLRBindings.cs", fileContent); AssetDatabase.Refresh(); //这里必须要刷新 //2.生成DLL ScriptBuildTools.BuildDll(outpath, platform, mode); //3.预绑定 //GenPreCLRBinding(); //4.生成自动分析绑定 GenCLRBindingByAnalysis(platform, outpath); AssetDatabase.Refresh(); //触发bd环境周期 BDFrameEditorBehaviorHelper.OnEndBuildDLL(outpath); AssetHelper.GenPackageBuildInfo(outpath, platform); Debug.Log("脚本打包完毕"); }
/// <summary> /// 生成sqlite /// 默认导出到当前平台目录下 /// </summary> /// <param name="ouptputPath">自定义路径</param> public static void AllExcel2SQLite(string ouptputPath, RuntimePlatform platform, DBType dbType = DBType.Local) { //触发bd环境周期 BDFrameEditorBehaviorHelper.OnBeginBuildSqlite(); var xlslFiles = GetAllConfigFiles(); 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环境周期 BDFrameEditorBehaviorHelper.OnEndBuildSqlite(ouptputPath); AssetHelper.AssetHelper.GenPackageBuildInfo(ouptputPath, platform); Debug.Log("导出Sqlite完成!"); }
/// <summary> /// 生成AssetBundle /// </summary> /// <param name="outputPath">导出目录</param> /// <param name="target">平台</param> /// <param name="options">打包参数</param> /// <param name="isHashName">是否为hash name</param> public static bool GenAssetBundle(string outputPath, RuntimePlatform platform, BuildTarget target, BuildAssetBundleOptions options = BuildAssetBundleOptions.ChunkBasedCompression, bool isHashName = false, string AES = "") { var _outputPath = Path.Combine(outputPath, BDApplication.GetPlatformPath(platform)); // var artOutputPath = IPath.Combine(_outputPath, "Art"); var buildInfoPath = IPath.Combine(artOutputPath, "BuildInfo.json"); //初始化 allfileHashMap = new Dictionary <string, string>(); var assetPaths = BDApplication.GetAllAssetsPath(); for (int i = 0; i < assetPaths.Count; i++) { assetPaths[i] = assetPaths[i].ToLower(); } /***********************新老资源依赖生成************************/ //获取老的配置 BuildInfo lastBuildInfo = new BuildInfo(); if (File.Exists(buildInfoPath)) { var content = File.ReadAllText(buildInfoPath); lastBuildInfo = JsonMapper.ToObject <BuildInfo>(content); } //获取当前配置 var newbuildInfo = GetAssetsInfo(assetPaths); //BD生命周期触发 BDFrameEditorBehaviorHelper.OnBeginBuildAssetBundle(newbuildInfo); // if (File.Exists(buildInfoPath)) { string targetPath = artOutputPath + "/BuildInfo.old.json"; File.Delete(targetPath); File.Move(buildInfoPath, targetPath); } FileHelper.WriteAllText(buildInfoPath, JsonMapper.ToJson(newbuildInfo)); //获取改动的数据 var changedBuildInfo = GetChangedAssets(lastBuildInfo, newbuildInfo); // newbuildInfo = null; //防止后面再用 if (changedBuildInfo.AssetDataMaps.Count == 0) { Debug.Log("无资源改变,不需要打包!"); return(false); } #region 整理依赖关系 //1.把依赖资源替换成AB Name, foreach (var asset in newbuildInfo.AssetDataMaps.Values) { for (int i = 0; i < asset.DependList.Count; i++) { var da = asset.DependList[i]; var dependAssetData = newbuildInfo.AssetDataMaps[da]; //替换成真正AB名 if (!string.IsNullOrEmpty(dependAssetData.ABName)) { asset.DependList[i] = dependAssetData.ABName; } } //去重 asset.DependList = asset.DependList.Distinct().ToList(); asset.DependList.Remove(asset.ABName); } var runtimeStr = "/runtime/"; if (isHashName) { //使用guid 作为ab名 foreach (var asset in newbuildInfo.AssetDataMaps) { var abname = AssetDatabase.AssetPathToGUID(asset.Value.ABName); if (!string.IsNullOrEmpty(abname)) //不存在的资源(如ab.shader之类),则用原名 { asset.Value.ABName = abname; } else { if (asset.Value.ABName != "shaders.ab") { Debug.LogError("获取GUID失败:" + asset.Value.ABName); } } for (int i = 0; i < asset.Value.DependList.Count; i++) { var dependAssetName = asset.Value.DependList[i]; abname = AssetDatabase.AssetPathToGUID(dependAssetName); if (!string.IsNullOrEmpty(abname)) //不存在的资源(如ab.shader之类),则用原名 { asset.Value.DependList[i] = abname; } else { Debug.LogError("获取GUID失败:" + dependAssetName); } } } } else { //2.整理runtime路径 替换路径名为Resource规则的名字 foreach (var asset in newbuildInfo.AssetDataMaps) { if (asset.Key.Contains(runtimeStr)) { var newName = asset.Value.ABName; //移除runtime之前的路径、后缀 var index = newName.IndexOf(runtimeStr); newName = newName.Substring(index + 1); //runtimeStr.Length); var extension = Path.GetExtension(newName); if (!string.IsNullOrEmpty(extension)) { newName = newName.Replace(extension, ""); } //刷新整个列表替换 foreach (var _asset in newbuildInfo.AssetDataMaps) { var oldName = asset.Key.ToLower(); //ab替换 if (_asset.Value.ABName == oldName) { _asset.Value.ABName = newName; } //依赖替换 for (int i = 0; i < _asset.Value.DependList.Count; i++) { if (_asset.Value.DependList[i] == oldName) { _asset.Value.DependList[i] = newName; } } } } } } #endregion #region 生成Runtime使用的Config //根据buildinfo 生成加载用的 Config //1.只保留Runtime目录下的配置 ManifestConfig config = new ManifestConfig(); config.IsHashName = isHashName; // foreach (var item in newbuildInfo.AssetDataMaps) { //runtime路径下, //改成用Resources加载规则命名的key if (item.Key.Contains(runtimeStr)) { var key = item.Key; //移除runtime之前的路径、后缀 var index = key.IndexOf(runtimeStr); if (config.IsHashName) { key = key.Substring(index + runtimeStr.Length); //hash要去掉runtime } else { key = key.Substring(index + 1); // 保留runtime } key = key.Replace(Path.GetExtension(key), ""); //添加manifest var mi = new ManifestItem(item.Value.ABName, (ManifestItem.AssetTypeEnum)item.Value.Type, new List <string>(item.Value.DependList)); config.ManifestMap[key] = mi; } } //写入 FileHelper.WriteAllText(artOutputPath + "/Config.json", JsonMapper.ToJson(config)); #endregion #region 设置ABname /***********************开始设置build ab************************/ //设置AB name foreach (var changedAsset in changedBuildInfo.AssetDataMaps) { //根据改变的ChangedAssets,获取Asset的资源 var key = changedAsset.Key; var asset = newbuildInfo.AssetDataMaps[changedAsset.Key]; //设置ABName 有ab的则用ab ,没有就用configpath string abname = asset.ABName; // var ai = GetAssetImporter(key); if (ai) { ai.assetBundleName = abname; } } #endregion //3.生成AssetBundle BuildAssetBundle(target, _outputPath, options); //4.清除AB Name RemoveAllAssetbundleName(); AssetImpoterCacheMap.Clear(); //the end.删除无用文件 var delFiles = Directory.GetFiles(artOutputPath, "*", SearchOption.AllDirectories); foreach (var df in delFiles) { var ext = Path.GetExtension(df); if (ext == ".meta" || ext == ".manifest") { File.Delete(df); } } //BD生命周期触发 BDFrameEditorBehaviorHelper.OnEndBuildAssetBundle(outputPath); AssetHelper.AssetHelper.GenPackageBuildInfo(outputPath, platform); return(true); }