/// <summary> /// 打包资源 /// </summary> public void BuildAsset() { RuntimePlatform platform = RuntimePlatform.Android; BuildTarget buildTarget = BuildTarget.Android; if (isSelectAndroid) { platform = RuntimePlatform.Android; buildTarget = BuildTarget.Android; } else if (isSelectIOS) { platform = RuntimePlatform.IPhonePlayer; buildTarget = BuildTarget.iOS; } var outPath = exportPath + "/" + BApplication.GetPlatformPath(platform); var config = GameObject.Find("BDFrame").GetComponent <Config>(); //根据版本进入不同打包模式 if (config.Data.AssetBundleManagerVersion == AssetBundleManagerVersion.V1) { AssetBundleEditorTools.GenAssetBundle(outPath, buildTarget, options); } else if (config.Data.AssetBundleManagerVersion == AssetBundleManagerVersion.V2_experiment) { AssetBundleEditorToolsV2.GenAssetBundle(outPath, buildTarget, options, AES: AES); } AssetDatabase.Refresh(); Debug.Log("资源打包完毕"); }
/// <summary> /// 打包资源 /// </summary> public void BuildAsset() { RuntimePlatform platform = RuntimePlatform.Android; BuildTarget buildTarget = BuildTarget.Android; // if (isSelectWindows) // { // platform = RuntimePlatform.WindowsPlayer; // buildTarget = BuildTarget.StandaloneWindows; // } // else if (isSelectAndroid) { platform = RuntimePlatform.Android; buildTarget = BuildTarget.Android; } else if (isSelectIOS) { platform = RuntimePlatform.IPhonePlayer; buildTarget = BuildTarget.iOS; } AssetBundleEditorTools.GenAssetBundle(exportPath + "/" + BApplication.GetPlatformPath(platform), buildTarget, options); AssetDatabase.Refresh(); Debug.Log("资源打包完毕"); }
/// <summary> /// 更新服务器配置 /// </summary> /// <param name="callback"></param> /// <returns></returns> private IEnumerator UpdateServerConfig(Action callback) { var url = string.Format("{0}/{1}/{2}", Data.FileServerUrl, BApplication.GetPlatformPath(Application.platform), "GameConfig.json"); Debug.Log(url); UnityWebRequest uwq = UnityWebRequest.Get(url); GameConfig gconfig = null; yield return(uwq.SendWebRequest()); if (uwq.isDone && uwq.error == null) { var text = uwq.downloadHandler.text; if (!string.IsNullOrEmpty(text)) { gconfig = JsonMapper.ToObject <GameConfig>(text); BDebug.Log("使用服务器配置:\n" + text); } } else { BDebug.LogError("Game配置无法更新,使用本地"); } SetNewConfig(gconfig); callback?.Invoke(); }
/// <summary> /// SVN提交 /// </summary> static private void SVNCommit(SVNProcessor svnProcessor) { //存在仓库 var svntag = svnProcessor.LocalSVNRootPath + "/.svn"; if (Directory.Exists(svntag)) { //1.获取被删除文件提交 var delFiles = svnProcessor.GetStatus(SVNProcessor.Status.Deleted); svnProcessor.Delete(delFiles); //2.获取支持的目录,提交 foreach (var platform in BApplication.SupportPlatform) { var p = BApplication.GetPlatformPath(platform); var path = Path.Combine(svnProcessor.LocalSVNRootPath, p); if (Directory.Exists(path)) { //添加文件夹 svnProcessor.AddFloder(path); //添加所有文件 var fs = Directory.GetFiles(path, "*", SearchOption.AllDirectories); svnProcessor.Add(fs); } } //提交 svnProcessor.Commit(); } }
private void Onclick_DownLoadAndLaunch() { //删除本地的文件 var cachedir = IPath.Combine(Application.persistentDataPath, BApplication.GetPlatformPath(Application.platform)); if (Directory.Exists(cachedir)) { Directory.Delete(cachedir, true); } var url = "http://" + this.inputField.text; VersionContorller.Start(UpdateMode.Repair, url, Application.persistentDataPath, (i, j) => { this.text_DownloadProcess.text = string.Format("{0}/{1}", i, j); //下载完毕 if (i == j) { this.text_DownloadProcess.text = "下载完毕"; //启动 GameObject.Find("BDFrame").GetComponent <BDLauncher>().Launch(); } }, (e) => { this.text_DownloadProcess.text = e; }); }
/// <summary> /// 生成AssetBundle /// </summary> /// <param name="outputPath">导出目录</param> /// <param name="target">平台</param> /// <param name="options">打包参数</param> /// <param name="isUseHashName">是否为hash name</param> public static bool GenAssetBundle(string outputPath, RuntimePlatform platform) { var buildTarget = BApplication.GetBuildTarget(platform); Build(buildTarget, outputPath); return(true); }
/// <summary> /// 初始化 /// </summary> /// <param name="path"></param> /// <param name="onInitEnd"></param> public void Init(string path, Action onInitEnd) { //多热更切换,需要卸载 if (this.loder != null) { this.UnloadAllAsset(); GC.Collect(); } this.AssetbundleMap = new Dictionary <string, AssetBundleWapper>(); this.allTaskGroupList = new List <LoaderTaskGroup>(); //1.设置加载路径 artRootPath = (path + "/" + BApplication.GetPlatformPath(Application.platform) + "/Art").Replace("\\", "/"); secArtRootPath = (Application.streamingAssetsPath + "/" + BApplication.GetPlatformPath(Application.platform) + "/Art") .Replace("\\", "/"); // string configPath = FindAsset("Config.json"); BDebug.Log("AssetBundle Version: V2", "red"); BDebug.Log("Art加载路径:" + configPath, "red"); // this.loder = new ManifestLoder(); this.loder.Load(configPath, onInitEnd); }
/// <summary> /// 分析dll生成 /// </summary> /// <param name="platform"></param> /// <param name="dllpath"></param> static private void GenCLRBindingByAnalysis(RuntimePlatform platform = RuntimePlatform.Lumin, string dllpath = "") { if (platform == RuntimePlatform.Lumin) { platform = Application.platform; } //默认读StreammingAssets下面path if (dllpath == "") { dllpath = Application.streamingAssetsPath + "/" + BApplication.GetPlatformPath(platform) + DLLPATH; } //不参与自动绑定的 List <Type> excludeTypes = new List <Type>(); // excludeTypes.AddRange(manualBindingTypes); excludeTypes.AddRange(preBindingTypes); //用新的分析热更dll调用引用来生成绑定代码 var targetPath = "Assets/Code/Game/ILRuntime/Binding/Analysis"; ILRuntimeHelper.LoadHotfix(dllpath, false); BindingCodeGenerator.GenerateAnalysisBindingCode(ILRuntimeHelper.AppDomain, targetPath, blackTypes: excludeTypes); ILRuntimeHelper.Close(); AssetDatabase.Refresh(); //暂时先不处理 }
/// <summary> /// 脚本加载入口 /// </summary> /// <param name="loadPathTypeType"></param> /// <param name="runMode"></param> /// <param name="mainProjectTypes">UPM隔离了dll,需要手动传入</param> static public void Init(AssetLoadPathType loadPathTypeType, HotfixCodeRunMode runMode, Type[] mainProjectTypes, Action <bool> clrBindingAction) { CLRBindAction = clrBindingAction; if (loadPathTypeType == AssetLoadPathType.Editor) { BDebug.Log("【ScriptLaunch】Editor(非热更)模式!"); //反射调用,防止编译报错 var assembly = Assembly.GetExecutingAssembly(); var type = assembly.GetType("BDLauncherBridge"); var method = type.GetMethod("Start", BindingFlags.Public | BindingFlags.Static); //添加框架部分的type,热更下不需要,打包会把框架的部分打进去 var list = new List <Type>(); list.AddRange(mainProjectTypes); list.AddRange(typeof(BDLauncher).Assembly.GetTypes()); method.Invoke(null, new object[] { list.ToArray(), null }); } else { BDebug.Log("【ScriptLaunch】热更模式!"); var path = GameConfig.GetLoadPath(loadPathTypeType); path = Path.Combine(path, BApplication.GetRuntimePlatformPath()); //加载dll var dllPath = Path.Combine(path, DLL_PATH); LoadHotfixDLL(dllPath, runMode, mainProjectTypes); } }
private bool CheckVersionDatabaseIsValid() { bool isValidate = true; BApplication appBusiness = new BApplication(); VersionStatus versionStatusObj = appBusiness.GetLastDatabaseVersion(); string[] atlasVersionStrArray = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString().Split('.'); int[] atlasVersionIntArray = Array.ConvertAll(atlasVersionStrArray, s => int.Parse(s)); string[] databaseVersionStrArray; if (versionStatusObj != null) { databaseVersionStrArray = versionStatusObj.Version.Split('.'); } else { databaseVersionStrArray = new string[4]; isValidate = false; return(isValidate); } int[] databaseVersionIntArray = Array.ConvertAll(databaseVersionStrArray, s => int.Parse(s)); for (int i = 0; i < atlasVersionIntArray.Count(); i++) { if (atlasVersionIntArray[i] != databaseVersionIntArray[i]) { isValidate = false; } } return(isValidate); }
/// <summary> /// 添加混淆 /// </summary> public void MixAssetBundle(string outpath, RuntimePlatform platform) { var mixAssets = GetMixAssets(); //构建ab管理器对象 AssetBundleMgrV2 abv2 = new AssetBundleMgrV2(); abv2.Init(outpath); // var mixAssetbundleItems = abv2.AssetConfigLoder.AssetbundleItemList.Where((i) => mixAssets.Contains(i.AssetBundlePath)).ToArray(); Debug.Log("<color=green>--------------------开始混淆Assetbundle------------------------</color>"); //开始混淆AssetBundle for (int i = 0; i < abv2.AssetConfigLoder.AssetbundleItemList.Count; i++) { //源AB var sourceItem = abv2.AssetConfigLoder.AssetbundleItemList[i]; //非混合文件、ab不存在、mix过 if (mixAssetbundleItems.Contains(sourceItem) || sourceItem.AssetBundlePath == null || sourceItem.Mix > 0) { continue; } var idx = (int)(Random.Range(0, (mixAssetbundleItems.Length - 1) * 10000) / 10000); var mixItem = mixAssetbundleItems[idx]; // var mixBytes = File.ReadAllBytes(IPath.Combine(outpath, BApplication.GetPlatformPath(platform), BResources.ART_ASSET_ROOT_PATH, mixItem.AssetBundlePath)); var abpath = IPath.Combine(outpath, BApplication.GetPlatformPath(platform), BResources.ART_ASSET_ROOT_PATH, sourceItem.AssetBundlePath); var abBytes = File.ReadAllBytes(abpath); //拼接 var outbytes = new byte[mixBytes.Length + abBytes.Length]; Array.Copy(mixBytes, 0, outbytes, 0, mixBytes.Length); Array.Copy(abBytes, 0, outbytes, mixBytes.Length, abBytes.Length); //写入 FileHelper.WriteAllBytes(abpath, outbytes); var hash = FileHelper.GetMurmurHash3(abpath); //相同ab的都进行赋值,避免下次重新被修改。 foreach (var item in abv2.AssetConfigLoder.AssetbundleItemList) { if (sourceItem.AssetBundlePath.Equals(item.AssetBundlePath)) { item.Mix = mixBytes.Length; item.Hash = hash; } } //sourceItem.Mix = mixBytes.Length; //混淆 Debug.Log("【Assetbundle混淆】" + sourceItem.AssetBundlePath); } //重新写入配置 abv2.AssetConfigLoder.OverrideConfig(); Debug.Log("<color=green>--------------------混淆Assetbundle完毕------------------------</color>"); }
public DevResourceMgr() { willdoTaskSet = new HashSet <int>(); allTaskList = new List <LoaderTaskGroup>(); objsMap = new Dictionary <string, UnityEngine.Object>(); // allResourceList = BApplication.GetAllAssetsPath(); }
/// <summary> /// 保存母包资源info /// </summary> /// <param name="ouptputPath"></param> /// <param name="platform"></param> /// <param name="info"></param> static public void SaveBasePackageBuildInfo(string ouptputPath, RuntimePlatform platform, BasePackageAssetsBuildInfo info) { //转json var content = JsonMapper.ToJson(info); //写入本地 var path = IPath.Combine(ouptputPath, BApplication.GetPlatformPath(platform), BResources.PACKAGE_BUILD_INFO_PATH); FileHelper.WriteAllText(path, content); }
/// <summary> /// 编译模式 /// </summary> /// <param name="mode"></param> static public void RoslynBuild(ScriptBuildTools.BuildMode mode, string outpath = null) { var targetPath = "Assets/Code/Game/ILRuntime/Binding/Analysis"; //分析之前先删除,然后生成临时文件防止报错 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(); //这里必须要刷新 //没指定,走默认模式 if (string.IsNullOrEmpty(outpath)) { //1.build dll var outpath_win = Application.streamingAssetsPath + "/" + BApplication.GetPlatformPath(Application.platform); ScriptBuildTools.BuildDll(outpath_win, mode); //2.同步到其他两个目录 var outpath_android = Application.streamingAssetsPath + "/" + BApplication.GetPlatformPath(RuntimePlatform.Android) + DLLPATH; var outpath_ios = Application.streamingAssetsPath + "/" + BApplication.GetPlatformPath(RuntimePlatform.IPhonePlayer) + DLLPATH; var source = outpath_win + DLLPATH; var bytes = File.ReadAllBytes(source); if (source != outpath_android) { FileHelper.WriteAllBytes(outpath_android, bytes); } if (source != outpath_ios) { FileHelper.WriteAllBytes(outpath_ios, bytes); } } else { //指定了直接 build ScriptBuildTools.BuildDll(outpath, mode); } //3.预绑定 GenPreCLRBinding(); //4.生成AnalysisCLRBinding GenCLRBindingByAnalysis(); AssetDatabase.Refresh(); Debug.Log("脚本打包完毕"); }
/// <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(); //最后,完成初始化 IsInited = true; // Debug.Log("框架编辑器环境初始化成功!"); } catch (Exception e) { Debug.LogError("框架编辑器环境初始化失败!"); Debug.LogError(e); throw; } }
/// <summary> /// 删除拷贝的资源 /// </summary> /// <param name="targetpath"></param> /// <param name="platform"></param> static public void DeleteCopyAssets(string targetpath, RuntimePlatform platform) { targetpath = IPath.Combine(targetpath, BApplication.GetPlatformPath(platform)); //优先删除拷贝的美术资源,防止构建完再导入 其他资源等工作流完全切入DevOps再进行删除 var copyArtPath = IPath.Combine(targetpath, BResources.ART_ASSET_ROOT_PATH); if (Directory.Exists(copyArtPath)) { Directory.Delete(copyArtPath, true); } }
/// <summary> /// 提示UI /// </summary> void TipsGUI() { GUILayout.Label("2.资源打包", EditorGUIHelper.TitleStyle); GUILayout.Space(5); GUILayout.Label("资源根目录:"); foreach (var root in BApplication.GetAllRuntimeDirects()) { GUILayout.Label(root); } GUILayout.Label(string.Format("AB输出目录:{0}", exportPath)); options = (BuildAssetBundleOptions)EditorGUILayout.EnumPopup("压缩格式:", options); }
/// <summary> /// 获取母包资源构建信息 /// </summary> /// <returns></returns> static public BasePackageAssetsBuildInfo GetPacakgeBuildInfo(string ouptputPath, RuntimePlatform platform) { var path = IPath.Combine(ouptputPath, BApplication.GetPlatformPath(platform), BResources.PACKAGE_BUILD_INFO_PATH); var buildinfo = new BasePackageAssetsBuildInfo(); if (File.Exists(path)) { var text = File.ReadAllText(path); buildinfo = JsonMapper.ToObject <BasePackageAssetsBuildInfo>(text); } return(buildinfo); }
/// <summary> /// 清理旧的persistent资源 /// </summary> static private void ClearOldPersistentAssets() { var runtimes = BApplication.SupportPlatform; foreach (var runtime in runtimes) { var path = IPath.Combine(Application.persistentDataPath, BApplication.GetPlatformPath(runtime)); if (Directory.Exists(path)) { Directory.Delete(path, true); } } }
/// <summary> /// 获取分包设置路径 /// </summary> /// <param name="rootPath"></param> /// <param name="platform"></param> /// <returns></returns> static public string GetAssetsSubPackageInfoPath(string rootPath, RuntimePlatform platform, string subPackageName) { //旧版本兼容逻辑 if (subPackageName.StartsWith("ServerAssetsSubPackage_")) { return(IPath.Combine(rootPath, BApplication.GetPlatformPath(platform), subPackageName)); } else { var subPackagePath = string.Format(BResources.SERVER_ASSETS_SUB_PACKAGE_INFO_PATH, subPackageName); return(IPath.Combine(rootPath, BApplication.GetPlatformPath(platform), subPackagePath)); } }
/// <summary> /// 资源转hash /// </summary> /// <param name="path"></param> /// <param name="uploadHttpApi"></param> static public void PublishAssetsToServer(string path) { foreach (var platform in BApplication.SupportPlatform) { //资源路径 var sourcePath = IPath.Combine(path, BApplication.GetPlatformPath(platform)); //大概判断原资源是否存在 if (Directory.Exists(sourcePath)) { var files = Directory.GetFiles(sourcePath, "*", SearchOption.AllDirectories); if (files.Length < 5) { continue; } } else { continue; } //输出路径 var outputPath = IPath.Combine(IPath.ReplaceBackSlash(path), UPLOAD_FOLDER_SUFFIX, BApplication.GetPlatformPath(platform)); if (Directory.Exists(sourcePath)) { //对比Assets.info 是否一致 var sourceAssetsInfoPath = IPath.Combine(sourcePath, BResources.ASSETS_INFO_PATH); var outputAssetsInfoPath = IPath.Combine(outputPath, BResources.ASSETS_INFO_PATH); if (File.Exists(sourceAssetsInfoPath) && File.Exists(outputAssetsInfoPath)) { var sourceHash = FileHelper.GetMurmurHash3(sourceAssetsInfoPath); var outputHash = FileHelper.GetMurmurHash3(outputAssetsInfoPath); if (sourceHash == outputHash) { Debug.Log("【PublishPipeline】资源无改动,无需重新生成服务器文件. -" + BApplication.GetPlatformPath(platform)); continue; } } //获取资源版本号 var basePckInfo = GlobalAssetsHelper.GetPackageBuildInfo(path, platform); var versionNum = basePckInfo.Version; //发布资源处理前,处理前回调 BDFrameworkPipelineHelper.OnBeginPublishAssets(platform, sourcePath, versionNum); //处理资源 var outdir = GenServerHashAssets(path, platform, versionNum); //发布资源处理后,通知回调 BDFrameworkPipelineHelper.OnEndPublishAssets(platform, outdir, versionNum); Debug.Log("发布资源处理完成! 请继承PublishPipeline生命周期,完成后续自动化部署到自己的文件服务器!"); } } }
/// <summary> /// 是否存在资源文件 /// </summary> /// <param name="platform"></param> /// <param name="serverAsset"></param> /// <returns></returns> static public bool IsExsitAsset(RuntimePlatform platform, string assetName, string assetHashName) { //本地是否下载过hash文件(之前下到一半就中止了) var persistentHashPath = IPath.Combine(BApplication.persistentDataPath, BApplication.GetPlatformPath(platform), assetHashName); if (File.Exists(persistentHashPath)) { var hash = FileHelper.GetMurmurHash3(persistentHashPath); if (assetHashName.Equals(hash)) { return(true); } else { File.Delete(persistentHashPath); } } //persistent判断 var persistentAssetPath = IPath.Combine(BApplication.persistentDataPath, BApplication.GetPlatformPath(platform), assetName); if (File.Exists(persistentAssetPath)) { return(true); } /************母包资源的判断*************/ if (Application.isEditor && BDLauncher.Inst.GameConfig.ArtRoot == AssetLoadPathType.DevOpsPublish) { //devops var devopsAssetPath = IPath.Combine(BApplication.DevOpsPublishAssetsPath, BApplication.GetPlatformPath(platform), assetName); if (File.Exists(devopsAssetPath)) { return(true); } } else { //Streaming 文件判断,无需Streaming前缀 var streamingAssetPath = IPath.Combine(BApplication.GetPlatformPath(platform), assetName); if (BetterStreamingAssets.FileExists(streamingAssetPath)) { return(true); } } return(false); }
/// <summary> /// 加载本地的Asset.info /// </summary> private List <AssetItem> LoadLocalAssetInfo(RuntimePlatform platform) { var retList = new List <AssetItem>(); //优先加载persistent的Assets.info var persistentAssetInfoPath = BResources.GetAssetsInfoPath(BApplication.persistentDataPath, platform); if (File.Exists(persistentAssetInfoPath)) { var content = File.ReadAllText(persistentAssetInfoPath); retList = CsvSerializer.DeserializeFromString <List <AssetItem> >(content); } //streaming 和其他的Assets.info else { //根据加载模式不同,寻找不同目录下的其他配置 //打包时,本地会带一份ServerAssets.info以标记当前包携带的资源 var loadArtRoot = BDLauncher.Inst.GameConfig.ArtRoot; switch (loadArtRoot) { case AssetLoadPathType.Persistent: case AssetLoadPathType.StreamingAsset: { //TODO :BSA 读取,不需要Streaming前缀 var steamingAssetsInfoPath = IPath.Combine(BApplication.GetPlatformPath(platform), BResources.ASSETS_INFO_PATH); //var steamingAssetsInfoPath = GetAssetsInfoPath(BDApplication.streamingAssetsPath, platform); if (BetterStreamingAssets.FileExists(steamingAssetsInfoPath)) { var content = BetterStreamingAssets.ReadAllText(steamingAssetsInfoPath); retList = CsvSerializer.DeserializeFromString <List <AssetItem> >(content); } } break; case AssetLoadPathType.DevOpsPublish: { var path = GameConfig.GetLoadPath(loadArtRoot); var devopsAssetInfoPath = BResources.GetAssetsInfoPath(path, platform); if (File.Exists(devopsAssetInfoPath)) { var content = File.ReadAllText(devopsAssetInfoPath); retList = CsvSerializer.DeserializeFromString <List <AssetItem> >(content); } } break; } } return(retList); }
/// <summary> /// 初始化 /// </summary> /// <param name="rootPath"></param> public void Init(string rootPath) { //多热更切换,需要卸载 if (this.AssetConfigLoder != null) { this.UnloadAllAsset(); } var platformPath = BApplication.GetRuntimePlatformPath(); //1.设置加载路径 if (Application.isEditor) { firstArtDirectory = IPath.Combine(rootPath, platformPath, BResources.ART_ASSET_ROOT_PATH); secArtDirectory = IPath.Combine(Application.streamingAssetsPath, platformPath, BResources.ART_ASSET_ROOT_PATH); // } else { firstArtDirectory = IPath.Combine(Application.persistentDataPath, platformPath, BResources.ART_ASSET_ROOT_PATH); secArtDirectory = IPath.Combine(Application.streamingAssetsPath, platformPath, BResources.ART_ASSET_ROOT_PATH); // } //2.路径替换 firstArtDirectory = IPath.ReplaceBackSlash(firstArtDirectory); secArtDirectory = IPath.ReplaceBackSlash(secArtDirectory); //3.加载ArtConfig this.AssetConfigLoder = new AssetbundleConfigLoder(); var assetconfigPath = ""; var assetTypePath = ""; if (Application.isEditor) { assetconfigPath = IPath.Combine(rootPath, platformPath, BResources.ART_ASSET_CONFIG_PATH); assetTypePath = IPath.Combine(rootPath, platformPath, BResources.ART_ASSET_TYPES_PATH); } else { //真机环境config在persistent,跟dll和db保持一致 assetconfigPath = IPath.Combine(Application.persistentDataPath, platformPath, BResources.ART_ASSET_CONFIG_PATH); assetTypePath = IPath.Combine(Application.persistentDataPath, platformPath, BResources.ART_ASSET_TYPES_PATH); } this.AssetConfigLoder.Load(assetconfigPath, assetTypePath); //开始异步任务刷新 IEnumeratorTool.StartCoroutine(this.IE_AsyncTaskListUpdte()); BDebug.Log($"【AssetBundleV2】 firstDir:{firstArtDirectory}", "red"); BDebug.Log($"【AssetBundleV2】 secDir:{secArtDirectory}", "red"); }
/// <summary> /// 提示UI /// </summary> void TipsGUI() { GUILayout.Label("2.资源打包", EditorGUIHelper.LabelH2); GUILayout.Space(5); GUILayout.Label("Runtime目录:"); foreach (var root in BApplication.GetAllRuntimeDirects()) { GUILayout.Label(root); } GUILayout.Space(3); GUILayout.Label("AssetBundle输出目录:DevOps"); // //assetConfig.AESCode = EditorGUILayout.TextField("AES密钥(V2 only):", assetConfig.AESCode); //assetConfig.IsUseHashName = EditorGUILayout.Toggle("hash命名:", assetConfig.IsUseHashName); }
/// <summary> /// 清理persistent /// </summary> private void OnClick_ClearPersistent() { foreach (var runtime in BApplication.SupportPlatform) { var path = IPath.Combine(Application.persistentDataPath, BApplication.GetPlatformPath(runtime)); if (Directory.Exists(path)) { Directory.Delete(path, true); } } //清理完毕 var dirs = Directory.GetDirectories(Application.persistentDataPath, "*"); Debug.Log(Application.persistentDataPath); Debug.Log("清理完毕~,剩余目录:" + dirs.Length); }
/// <summary> /// 编译模式 /// </summary> /// <param name="mode"></param> static public void RoslynBuild(ScriptBuildTools.BuildMode mode, string outpath = null) { 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 if (string.IsNullOrEmpty(outpath)) { //1.build dll var outpath_win = Application.streamingAssetsPath + "/" + BApplication.GetPlatformPath(Application.platform); ScriptBuildTools.BuildDll(outpath_win, mode); } else { //指定了直接 build ScriptBuildTools.BuildDll(outpath, mode); } //3.预绑定 //GenPreCLRBinding(); //4.生成自动分析绑定 GenCLRBindingByAnalysis(); AssetDatabase.Refresh(); Debug.Log("脚本打包完毕"); }
static public void BDEditorInit() { #region 注册所以管理器,让管理器在编辑器下生效 //项目所有类 var types = typeof(BDLauncher).Assembly.GetTypes().ToList(); //编辑器所有类 var editorTypes = typeof(BDEditorMenuEnum).Assembly.GetTypes(); types.AddRange(editorTypes); List <IMgr> mgrs = new List <IMgr>(); foreach (var t in types) { if (t != null && t.BaseType != null && t.BaseType.FullName != null && t.BaseType.FullName.Contains(".ManagerBase`2")) { var i = t.BaseType.GetProperty("Inst").GetValue(null, null) as IMgr; mgrs.Add(i); continue; } } foreach (var t in types) { foreach (var mgr in mgrs) { mgr.CheckType(t); } } Debug.Log("BDFrameEditor:管理器注册完成"); #endregion BApplication.Init(); DebuggerServerProcessManager.Inst.Start(); BDEditorHelper.Init(); BResources.Load(""); //TODO //这一行还是不能加到框架层,应该还是:哪里用 哪里主动load, //然后用完了close(SqliteLoder.Close())。 //不然sql文件editor环境下一直被占用,很多麻烦事 // SqliteLoder.Load(Application.streamingAssetsPath); }
/// <summary> /// 生成所有资源 /// </summary> /// <param name="exportPath"></param> /// <param name="platform"></param> /// <param name="target"></param> static public void GenAllAssets(string exportPath, RuntimePlatform platform, BuildTarget target) { var outPath = exportPath + "/" + BApplication.GetPlatformPath(platform); if (Directory.Exists(outPath)) { Directory.Delete(outPath, true); } //1.打包资源 try { //搜集keywork ShaderCollection.GenShaderVariant(); AssetBundleEditorTools.GenAssetBundle(outPath, target); } catch (Exception e) { Debug.LogError(e.Message); return; } //2.编译脚本 try { EditorWindow_ScriptBuildDll.RoslynBuild(ScriptBuildTools.BuildMode.Release, outPath); } catch (Exception e) { Debug.LogError(e.Message); return; } //3.打包表格 try { Excel2SQLiteTools.GenExcel2SQLite(exportPath, platform); } catch (Exception e) { Debug.LogError(e.Message); } }
/// <summary> /// 打包ShaderOnly /// </summary> public static void BuildShadersAssetBundle() { AssetDatabase.StartAssetEditing(); { CollectShaderVariant(); var guid = AssetDatabase.AssetPathToGUID(BResources.ALL_SHADER_VARAINT_ASSET_PATH); List <AssetImporter> list = new List <AssetImporter>(); //依赖信息 var dependice = AssetDatabase.GetDependencies(BResources.ALL_SHADER_VARAINT_ASSET_PATH); foreach (var depend in dependice) { var type = AssetDatabase.GetMainAssetTypeAtPath(depend); if (type == typeof(Material) || type == typeof(ShaderVariantCollection)) { var ai = AssetImporter.GetAtPath(depend); ai.SetAssetBundleNameAndVariant(guid, null); Debug.Log("打包:" + depend); list.Add(ai); } } //开始编译 var outpath = IPath.Combine(BApplication.Library, "BDBuildTest", BApplication.GetRuntimePlatformPath()); if (Directory.Exists(outpath)) { Directory.Delete(outpath, true); } Directory.CreateDirectory(outpath); // var buildtarget = BApplication.GetBuildTarget(BApplication.RuntimePlatform); UnityEditor.BuildPipeline.BuildAssetBundles(outpath, BuildAssetBundleOptions.DeterministicAssetBundle | BuildAssetBundleOptions.ChunkBasedCompression, buildtarget); // foreach (var ai in list) { ai.SetAssetBundleNameAndVariant(null, null); } Debug.Log("测试AB已经输出:" + outpath); } AssetDatabase.StopAssetEditing(); }