public void Build(XRuntimePlatform platform, AssetCompressType compressType) { Debug.Log("[TinaX.VFS] Start build assets..."); if (ClearAssetBundleSignBeforeBuild) { VFSEditorUtil.RemoveAllAssetbundleSigns(); } Debug.Log(" handle assetbundle signs..."); RefreshAssetBundleSign(); Debug.Log(" build assetbundles by unity editor."); string packages_root_path; //VFS存放相关文件的根目录 string output_temp_path; //Unity自身打包后直接输出的目录 BuildAssetBundle(platform, compressType, out packages_root_path, out output_temp_path); #region 加载Build得到的AssetbundleManifest文件 string abmanifest_file_name = Path.GetFileName(output_temp_path); string abmanifest_path = Path.Combine(output_temp_path, abmanifest_file_name); AssetBundle ab_mainifest = AssetBundle.LoadFromFile(abmanifest_path); mAssetBundleManifest = ab_mainifest.LoadAsset <AssetBundleManifest>("AssetBundleManifest"); #endregion HandleVFSFiles(packages_root_path, output_temp_path, platform); SaveAssetHashFiles(Path.Combine(packages_root_path, VFSEditorConst.PROJECT_VFS_FILE_FOLDER_DATA)); MakeEditorBuildInfo(packages_root_path); MakeBuildInfo(packages_root_path); MakeVFSConfig(packages_root_path, Config); if (CopyToStreamingAssetsFolder) { CopyToStreamingAssets(packages_root_path, XPlatformUtil.GetNameText(platform)); } if (ClearAssetBundleSignAfterBuild) { VFSEditorUtil.RemoveAllAssetbundleSigns(); } Debug.Log("[TinaX.VFS] Build Finished."); }
public void BuildAssetBundle(XRuntimePlatform platform, AssetCompressType compressType) { this.BuildAssetBundle(platform, compressType, out _, out _); }
public void BuildAssetBundle(XRuntimePlatform platform, AssetCompressType compressType, out string output_folder, out string temp_output_folder) { var buildTarget = XPlatformEditorUtil.GetBuildTarget(platform); var target_name = XPlatformUtil.GetNameText(platform); output_folder = Path.Combine(VFSEditorConst.PROJECT_VFS_SOURCE_PACKAGES_ROOT_PATH, target_name); string build_output_folder = Path.Combine(output_folder, "build_temp"); temp_output_folder = build_output_folder; if (ClearOutputFolder) { XDirectory.DeleteIfExists(output_folder, true); } XDirectory.CreateIfNotExists(output_folder); XDirectory.CreateIfNotExists(temp_output_folder); //压缩方法 BuildAssetBundleOptions build_opt = BuildAssetBundleOptions.None; switch (compressType) { default: case AssetCompressType.LZ4: build_opt = BuildAssetBundleOptions.ChunkBasedCompression; break; case AssetCompressType.LZMA: build_opt = BuildAssetBundleOptions.None; break; case AssetCompressType.None: build_opt = BuildAssetBundleOptions.UncompressedAssetBundle; break; } //强制重新构建 if (ForceRebuild) { build_opt = build_opt | BuildAssetBundleOptions.ForceRebuildAssetBundle; } //严格模式 if (StrictMode) { build_opt = build_opt | BuildAssetBundleOptions.StrictMode; } //Hash保持一致 build_opt = build_opt | BuildAssetBundleOptions.DeterministicAssetBundle; //叫Unity来打ab包 BuildPipeline.BuildAssetBundles(build_output_folder, build_opt, buildTarget); //打包完了,把所有打包得到的AssetBundle文件记录下来 string ab_extension = Config.AssetBundleFileExtension; if (!ab_extension.StartsWith(".")) { ab_extension = "." + ab_extension; } string[] files = Directory.GetFiles(build_output_folder, $"*{ab_extension}", SearchOption.AllDirectories); #region temp下的目录完全hash //var hashBook = new FilesHashBook(); //List<FilesHashBook.FileHash> temp_hash_list = new List<FilesHashBook.FileHash>(); //int build_output_folder_len = build_output_folder.Length + 1; //foreach (var file in files) //{ // string pure_path = file.Substring(build_output_folder_len, file.Length - build_output_folder_len); // if (pure_path.IndexOf("\\") != -1) // pure_path = pure_path.Replace("\\", "/"); // temp_hash_list.Add(new FilesHashBook.FileHash() // { // p = pure_path, // h = XFile.GetMD5(file, true) // }); //} //hashBook.Files = temp_hash_list.ToArray(); //string hashBook_path = Path.Combine(build_output_folder, VFSConst.ABsHashFileName); //XFile.DeleteIfExists(hashBook_path); //string hashBook_json = JsonUtility.ToJson(hashBook); //File.WriteAllText(hashBook_path, hashBook_json, Encoding.UTF8); #endregion }
private void OnGUI() { GUILayout.BeginVertical(style_body); #region Profile 选择 if (xprofiles == null || (select_xprofile - 1) > xprofiles.Length) { refreshXprofilesCacheData(); } if (mDevelopMode) { GUILayout.Label("[Develop Mode]", style_warning); } GUILayout.BeginHorizontal(style_profile_selector); GUILayout.Label("Profile:", GUILayout.Width(55)); //select_xprofile = EditorGUILayout.Popup(select_xprofile, xprofiles); GUILayout.Label(xprofiles[select_xprofile]); if (GUILayout.Button(VFSBuilderI18N.SwitchProfile, GUILayout.Width(50))) { SettingsService.OpenProjectSettings(XEditorConst.ProjectSetting_CorePath); } GUILayout.EndHorizontal(); #endregion if (xprofiles != null && xprofiles.Length > 0) { cur_select_xprofile_name = xprofiles[select_xprofile]; } #region 平台选择 EditorGUILayout.BeginHorizontal(); GUILayout.Label(VFSBuilderI18N.PlatformTarget, GUILayout.MaxWidth(100)); cur_select_platform = (XRuntimePlatform)EditorGUILayout.EnumPopup(cur_select_platform); EditorGUILayout.EndHorizontal(); #endregion #region 严格模式 EditorGUILayout.BeginHorizontal(); GUILayout.Label(VFSBuilderI18N.strictMode, GUILayout.Width(100)); cur_strictMode = EditorGUILayout.Toggle(cur_strictMode); EditorGUILayout.EndHorizontal(); #endregion #region 压缩设置 EditorGUILayout.BeginHorizontal(); GUILayout.Label(VFSBuilderI18N.AssetCompressType, GUILayout.MaxWidth(100)); cur_select_compress = (AssetCompressType)EditorGUILayout.EnumPopup(cur_select_compress); EditorGUILayout.EndHorizontal(); #endregion #region 制到StreamingAssets EditorGUILayout.BeginHorizontal(); GUILayout.Label(VFSBuilderI18N.CopyToStramingAssetPath, GUILayout.MaxWidth(200)); cur_copyToStreamingAssetFolder = EditorGUILayout.Toggle(cur_copyToStreamingAssetFolder); EditorGUILayout.EndHorizontal(); #endregion #region 在结束前清理AB标记 EditorGUILayout.BeginHorizontal(); GUILayout.Label(VFSBuilderI18N.ClearAllABSignBeforeStart); cur_clearAllABSign = EditorGUILayout.Toggle(cur_clearAllABSign); EditorGUILayout.EndHorizontal(); GUILayout.Label(VFSBuilderI18N.ClearAllABSignBeforeStart_Tips, EditorStyles.helpBox); #endregion #region 在结束后清理AB标记 EditorGUILayout.BeginHorizontal(); GUILayout.Label(VFSBuilderI18N.ClearAllABSignAfterFinish); cur_clearAllABSignAfterFinish = EditorGUILayout.Toggle(cur_clearAllABSignAfterFinish); EditorGUILayout.EndHorizontal(); #endregion #region 清理输出目录 EditorGUILayout.BeginHorizontal(); GUILayout.Label(VFSBuilderI18N.ClearOutputFolders); cur_ClearOutputFolder = EditorGUILayout.Toggle(cur_ClearOutputFolder); EditorGUILayout.EndHorizontal(); #endregion #region 强制重构建资源 EditorGUILayout.BeginHorizontal(); GUILayout.Label(VFSBuilderI18N.ForceRebuild); cur_ForceRebuild = EditorGUILayout.Toggle(cur_ForceRebuild); EditorGUILayout.EndHorizontal(); #endregion #region 管线 if (mPipeline_ready == false) { refreshBuildPipline(); } if (mList_pipeline != null && mList_pipeline.Count > 0) { GUILayout.Space(15); TinaXEditor.Utils.EditorGUIUtil.HorizontalLine(); GUILayout.Label("Builder Pipeline:"); v2_scroll_pipeline = EditorGUILayout.BeginScrollView(v2_scroll_pipeline); foreach (var type in mList_pipeline) { if (type.Namespace.IsNullOrEmpty()) { GUILayout.Label($"- {type.FullName} [{type.Assembly.ManifestModule.Name}]"); } else { GUILayout.Label($"- {type.Namespace}.{type.FullName} [{type.Assembly.ManifestModule.Name}]"); } } EditorGUILayout.EndScrollView(); } #endregion //#region Preview //GUILayout.BeginVertical(style_preview); //GUILayout.Label("Build Priview", EditorStyles.centeredGreyMiniLabel); //GUILayout.Label("Build Group:"); //GUILayout.FlexibleSpace(); //GUILayout.EndVertical(); //#endregion EditorGUILayout.Space(); if (GUILayout.Button("Build", style_btn_build)) { runBuild(); } if (GUILayout.Button(VFSBuilderI18N.RemoveAllAssetBundleSign)) { if (EditorUtility.DisplayDialog("Clear?", "Are you sure?", "yes", "no")) { VFSEditorUtil.RemoveAllAssetbundleSigns(true); } } if (GUILayout.Button(VFSBuilderI18N.CreateVersionRecord)) { CreateVersionRecordGUI.VFS_Platform = cur_select_platform; CreateVersionRecordGUI.OpenUI(); } EditorGUILayout.Space(); GUILayout.EndVertical(); }