static XCoreEditor() { //检查 TinaX Profile XDirectory.CreateIfNotExists(XEditorConst.EditorProjectSettingRootFolder); RefreshXProfile(); }
/// <summary> /// 保存BuildInfo /// </summary> /// <returns></returns> private void MakeBuildInfo(string packages_root_path) { var binfo = new BuildInfo(); binfo.BuildID = System.Guid.NewGuid().ToString(); //save main package string main_path = VFSUtil.GetMainPackage_BuildInfo_Path(packages_root_path); XFile.DeleteIfExists(main_path); XDirectory.CreateIfNotExists(Path.GetDirectoryName(main_path)); XConfig.SaveJson(binfo, main_path, AssetLoadType.SystemIO); //groups if (mEditorBuildInfo.list_total_extension != null && mEditorBuildInfo.list_total_extension.Count > 0) { foreach (var group in mEditorBuildInfo.list_total_extension) { string target_path = VFSUtil.GetExtensionGroup_BuildInfo_Path(packages_root_path, group); string group_root_path = VFSUtil.GetExtensionGroupFolder(packages_root_path, group); if (Directory.Exists(group_root_path)) { XFile.DeleteIfExists(target_path); XDirectory.CreateIfNotExists(Path.GetDirectoryName(target_path)); XConfig.SaveJson(binfo, target_path, AssetLoadType.SystemIO); } } } }
public DownloadHandlerVDisk(string save_target, int bufferSize = 4096, FileShare fileShare = FileShare.ReadWrite) : base(new byte[bufferSize]) { string directory = Path.GetDirectoryName(save_target); XDirectory.CreateIfNotExists(directory); mStream = new FileStream(save_target, FileMode.OpenOrCreate, FileAccess.Write, fileShare, bufferSize); }
/// <summary> /// 保存EditorBuildInfo /// </summary> /// <param name="package_root_path"></param> private void MakeEditorBuildInfo(string package_root_path) { mEditorBuildInfo.build_profile_name = curProfile.ProfileName; mEditorBuildInfo.ReadySave(); string path = VFSEditorUtil.Get_EditorBuildInfoPath(package_root_path); XFile.DeleteIfExists(path); XDirectory.CreateIfNotExists(Path.GetDirectoryName(path)); XConfig.SaveJson(mEditorBuildInfo, path, AssetLoadType.SystemIO); }
public void SaveGroupOptionFile(string package_root_path) { string target_path = VFSUtil.GetExtensionPackages_GroupOptions_FilePath(package_root_path, this.GroupName); XFile.DeleteIfExists(target_path); XDirectory.CreateIfNotExists(Path.GetDirectoryName(target_path)); string json = JsonUtility.ToJson(base.mOption); File.WriteAllText(target_path, json); }
private void SaveAssetHashFiles(string data_path) { XDirectory.CreateIfNotExists(data_path); //mainPackage string mainPackageHashPath = Path.Combine(data_path, VFSConst.AssetsHashFileName); var main_obj = new FilesHashBook(); main_obj.Files = asset_hash_book.ToArray(); XConfig.SaveJson(main_obj, mainPackageHashPath, AssetLoadType.SystemIO); string extGroupHashFolderPath = Path.Combine(data_path, VFSConst.ExtensionGroupAssetsHashFolderName); XDirectory.DeleteIfExists(extGroupHashFolderPath, true); Directory.CreateDirectory(extGroupHashFolderPath); //各个扩展组 foreach (var item in dict_asset_hash_book) { string g_path = Path.Combine(extGroupHashFolderPath, item.Key + ".json"); var obj = new FilesHashBook(); obj.Files = item.Value.ToArray(); XConfig.SaveJson(obj, g_path, AssetLoadType.SystemIO); } }
public static void RefreshManager(bool Normalization = false) { mConfig = XConfig.GetConfig <VFSConfigModel>(VFSConst.ConfigFilePath_Resources); if (mConfig == null) { return; } if (Normalization) { VFSUtil.NormalizationConfig(mConfig); } if (!VFSUtil.CheckConfiguration(mConfig, out var errorCode, out var folderError)) { string log_str = string.Empty; //配置文件校验未通过 switch (errorCode) { case VFSErrorCode.ConfigureGroupsConflict: //资源组规则未通过,log提示出来 log_str = VFSManagerEditorI18N.Log_ConfigureGroupsConflict; if (folderError != null && folderError.Length > 0) { foreach (var f in folderError) { log_str += $"\nGroup [{f.GroupName}] , FolderPath: {f.FolderPath}"; } } Debug.LogError(log_str); return; //直接不继续往下执行了 case VFSErrorCode.NoneGroup: //没有配置任何资源组 //这个问题不报Error return; case VFSErrorCode.SameGroupName: log_str = VFSManagerEditorI18N.Log_SameGroupName; Debug.LogError(log_str); return; } } Groups.Clear(); if (!mConfig.EnableVFS) { return; } //VFS Profile XDirectory.CreateIfNotExists(XEditorConst.EditorProjectSettingRootFolder); var profile_path = Path.Combine(XEditorConst.EditorProjectSettingRootFolder, VFSEditorConst.VFSProfileProjectSettingFileName); if (File.Exists(profile_path)) { //load VFSProfileEditor = XConfig.GetJson <VFSProfileModel>(profile_path, AssetLoadType.SystemIO, false); } else { //create profile editor file in "ProjectSetting" initProfileRecord(); //var json_text = JsonUtility.ToJson(VFSProfileEditor); XConfig.SaveJson(VFSProfileEditor, profile_path, AssetLoadType.SystemIO); } foreach (var group_opt in mConfig.Groups) { var _group_obj = new VFSEditorGroup(group_opt); Groups.Add(_group_obj); FolderPaths.AddRange(_group_obj.FolderPaths); foreach (var assetPath in _group_obj.AssetPaths) { if (!AssetPaths.Contains(assetPath)) { AssetPaths.Add(assetPath); } } } LastRefreshManagerTime = System.DateTime.UtcNow; }
private Dictionary <string, VersionBranch> mDict_Branches = new Dictionary <string, VersionBranch>(); //string: branch name public VFSVersionsManagerEditor() { mVersionData_BranchIndex_FolderPath = Path.Combine(mVersionDataFolderPath, "BrancheIndexes"); //mVersionData_Branches_Data_FolderPath = Path.Combine(mVersionDataFolderPath, "Branches"); mVersionBinary_Branches_FolderPath = Path.Combine(mVersionBinaryFolderPath, "Branches"); XDirectory.CreateIfNotExists(mVersionRootFolderPath); XDirectory.CreateIfNotExists(mVersionDataFolderPath); XDirectory.CreateIfNotExists(mVersionData_BranchIndex_FolderPath); #region 初始化版本数据 //主索引文件 bool flag_create = false; if (File.Exists(mVersionMainFilePath)) { try { mVersionMainData = XConfig.GetJson <VersionsModel>(mVersionMainFilePath, AssetLoadType.SystemIO, false); } catch { flag_create = true; } } else { flag_create = true; } if (flag_create) { mVersionMainData = new VersionsModel(); } if (mVersionMainData.branches == null) { mVersionMainData.branches = new string[0]; } //各个分支的配置文件 foreach (var branchName in mVersionMainData.branches) { string branchIndexFilePath = Path.Combine(mVersionData_BranchIndex_FolderPath, $"{branchName}.json"); bool flag_create_branch = false; if (File.Exists(branchIndexFilePath)) { try { var obj = XConfig.GetJson <VersionBranch>(branchIndexFilePath, AssetLoadType.SystemIO, false); if (obj != null) { if (mDict_Branches.ContainsKey(branchName)) { mDict_Branches[branchName] = obj; } else { mDict_Branches.Add(branchName, obj); } } } catch { flag_create_branch = true; } } else { flag_create_branch = true; } if (flag_create_branch) { var obj = new VersionBranch(); obj.BranchName = branchName; obj.BType = VersionBranch.BranchType.MainPackage; mDict_Branches.Add(branchName, obj); SaveBranchFile(ref obj); } } #endregion }
/// <summary> /// 添加版本记录 /// </summary> /// <param name=""></param> public void AddVersionRecord(string branchName, long versionCode, string versionName, string versionDesc, bool saveBinary, bool dialog = true, bool log = true) { //编辑器那边限制了不能添加“比最大版本号更小的版本号”的版本,(也就是说版本号只能变大),但是这里实际上没做这个限制。以后如果有需要,可以让编辑器UI上去掉限制。 if (mDict_Branches.TryGetValue(branchName, out var branch)) { //判断一下版本号啦 if (versionCode >= 0 && !branch.IsVersionCodeExists(versionCode)) { bool isMainPackage = (branch.BType == VersionBranch.BranchType.MainPackage); bool flag_process_error = false; //处理文件过程中如果出错则中断操作且不记录数据 string platform_name = XPlatformUtil.GetNameText(branch.Platform); string source_packages_folder_path = VFSEditorUtil.GetSourcePackagesFolderPath(platform_name); string data_folder = VFSEditorUtil.GetVersionDataFolderPath_InProjectVersion(branch.BranchName, versionCode); //存放数据的地方 string build_id = string.Empty; try { XDirectory.DeleteIfExists(data_folder, true); Directory.CreateDirectory(data_folder); //复制并存档assets_hash文件 string assets_hash_path = isMainPackage ? VFSEditorUtil.GetMainPackage_AssetsHashFilePath_InSourcePackagesFolder(platform_name) : VFSEditorUtil.GetExtensionGroup_AssetsHashFilePath_InSourcePackagesFolder(platform_name, branch.ExtensionGroupName); string assets_hash_target_path = Path.Combine(data_folder, VFSConst.AssetsHashFileName); if (File.Exists(assets_hash_path)) { File.Copy(assets_hash_path, assets_hash_target_path, true); } //复制并存档Manifest文件 string manifest_target_path = VFSEditorUtil.GetVersionData_Manifest_FolderOrFilePath(!isMainPackage, branchName, versionCode); string manifest_path = isMainPackage ? VFSEditorUtil.GetMainPackage_AssetBundleManifestsFolderPath_InSourcePackagesFolder(platform_name) : VFSEditorUtil.GetExtensionGroup_AssetBundleManifestPath_InInSourcePackagesFolder(platform_name, branch.ExtensionGroupName); if (isMainPackage) { if (Directory.Exists(manifest_path)) { XDirectory.CopyDir(manifest_path, manifest_target_path); } } else { if (File.Exists(manifest_path)) { File.Copy(manifest_path, manifest_target_path); } } //复制并存档AssetBundleHashs string ab_hash_path = isMainPackage ? VFSEditorUtil.GetMainPackage_AssetBundle_HashFiles_FolderPath_InSourcePackagesFolder(platform_name) : VFSEditorUtil.GetExtensionGroup_AssetBundle_HashFiles_Path_InInSourcePackagesFolder(platform_name, branch.ExtensionGroupName); string ab_hash_target_path = VFSEditorUtil.GetVersionData_AssetBundle_HashFile_FolderOrFilePath(!isMainPackage, branchName, versionCode); if (isMainPackage) { if (Directory.Exists(ab_hash_path)) { XDirectory.CopyDir(ab_hash_path, ab_hash_target_path); } } else { if (File.Exists(ab_hash_path)) { File.Copy(ab_hash_path, ab_hash_target_path); } } //复制并存档vfs config (main package) if (isMainPackage) { string vfs_config_path = VFSUtil.GetVFSConfigFilePath_InPackages(VFSEditorUtil.GetSourcePackagesFolderPath(platform_name)); if (File.Exists(vfs_config_path)) { string target_path = Path.Combine(data_folder, VFSConst.Config_Runtime_FileName); File.Copy(vfs_config_path, target_path, true); } } //Group Options if (!isMainPackage) { string group_option_path = VFSUtil.GetExtensionPackages_GroupOptions_FilePath(source_packages_folder_path, branch.ExtensionGroupName); if (File.Exists(group_option_path)) { string target_path = Path.Combine(data_folder, VFSConst.ExtensionGroup_GroupOption_FileName); File.Copy(group_option_path, target_path, true); } } //Group Info if (!isMainPackage) { string group_info_path = VFSUtil.GetExtensionGroup_GroupInfo_Path_InGroupPath(VFSUtil.GetExtensionGroupFolder(source_packages_folder_path, branch.ExtensionGroupName)); if (File.Exists(group_info_path)) { string target_path = Path.Combine(data_folder, VFSConst.VFS_ExtensionGroupInfo_FileName); File.Copy(group_info_path, target_path, true); } } //复制并存档editor build info string editor_build_info_path = VFSEditorUtil.Get_EditorBuildInfoPath(VFSEditorUtil.GetSourcePackagesFolderPath(platform_name)); if (File.Exists(editor_build_info_path)) { string target_path = VFSEditorUtil.GetVersionData_EditorBuildInfo_Path(branchName, versionCode); File.Copy(editor_build_info_path, target_path); } //复制并存档 build info string build_info_path = VFSUtil.GetMainPackage_BuildInfo_Path(VFSEditorUtil.GetSourcePackagesFolderPath(platform_name)); if (File.Exists(build_info_path)) { //存档 string target_path = VFSEditorUtil.GetVersionData_BuildInfo_Path(branchName, versionCode); File.Copy(build_info_path, target_path); //反写版本信息到source package string build_info_json = File.ReadAllText(target_path, Encoding.UTF8); var obj = JsonUtility.FromJson <BuildInfo>(build_info_json); build_id = obj.BuildID; //写出版本信息 var version_info = new PackageVersionInfo { version = versionCode, versionName = versionName, buildId = obj.BuildID, branch = branch.BranchName }; string version_info_path = isMainPackage ? VFSEditorUtil.Get_MainPackage_PackageVersionFilePath_InSourcePackages(platform_name) : VFSEditorUtil.Get_ExtensionGroups_PackageVersionFilePath_InSourcePackages(ref platform_name, ref branch.ExtensionGroupName); XFile.DeleteIfExists(version_info_path); XConfig.SaveJson(version_info, version_info_path, AssetLoadType.SystemIO); //检查当前StreamingAssets中是否有与之build id一致的情况,如果有,也写出 if (isMainPackage) { string buildinfo_in_stream = VFSUtil.GetMainPackage_BuildInfo_Path(VFSUtil.GetPackagesRootFolderInStreamingAssets(platform_name)); if (File.Exists(buildinfo_in_stream)) { try { var obj_stream = XConfig.GetJson <BuildInfo>(buildinfo_in_stream, AssetLoadType.SystemIO, false); if (obj_stream.BuildID == obj.BuildID) { //一致,写出 string target_stream = VFSUtil.GetMainPackage_VersionInfo_Path(VFSUtil.GetPackagesRootFolderInStreamingAssets(platform_name)); XConfig.SaveJson(version_info, target_stream, AssetLoadType.SystemIO); } } catch { } } } else { string buildinfo_in_stream = VFSUtil.GetExtensionGroup_BuildInfo_Path(VFSUtil.GetPackagesRootFolderInStreamingAssets(platform_name), branch.ExtensionGroupName); if (File.Exists(buildinfo_in_stream)) { try { var obj_stream = XConfig.GetJson <BuildInfo>(buildinfo_in_stream, AssetLoadType.SystemIO, false); if (obj_stream.BuildID == obj.BuildID) { //一致,写出 string target_stream = VFSUtil.GetExtensionGroup_VersionInfo_Path(VFSUtil.GetPackagesRootFolderInStreamingAssets(platform_name), branch.ExtensionGroupName); XConfig.SaveJson(version_info, target_stream, AssetLoadType.SystemIO); } } catch { } } } } } catch (Exception e) { XDirectory.DeleteIfExists(data_folder, true); flag_process_error = true; throw e; } //保存二进制文件 if (saveBinary && !flag_process_error) { string binary_path = VFSEditorUtil.Get_AssetsBinaryFolderPath_InVersion(branchName, versionCode); try { long total_count = 0; //把所有二进制文件直接全拷进去 string binary_path_temp = Path.Combine(binary_path, "temp"); string binary_path_temp_remote = Path.Combine(binary_path, "temp_remote"); XDirectory.DeleteIfExists(binary_path_temp, true); Directory.CreateDirectory(binary_path_temp); if (isMainPackage) { XDirectory.DeleteIfExists(binary_path_temp_remote, true); Directory.CreateDirectory(binary_path_temp_remote); } //移动文件 if (isMainPackage) { string local_path = VFSEditorUtil.Get_MainPackage_AssetsFolderPath_InSourcePackages(platform_name); int local_path_len = local_path.Length + 1; string[] local_files = Directory.GetFiles(local_path, "*.*", SearchOption.AllDirectories); if (local_files != null && local_files.Length > 0) { ArrayUtil.RemoveDuplicationElements(ref local_files); foreach (var item in local_files) { total_count++; string pure_path = item.Substring(local_path_len, item.Length - local_path_len); string target_path = Path.Combine(binary_path_temp, pure_path); XDirectory.CreateIfNotExists(Path.GetDirectoryName(target_path)); File.Copy(item, target_path); } } string remote_path = VFSEditorUtil.Get_MainPackage_RemoteAssetsFolderPath_InSourcePackages(platform_name); if (Directory.Exists(remote_path)) { int remote_path_len = remote_path.Length + 1; string[] remote_files = Directory.GetFiles(remote_path, "*.*", SearchOption.AllDirectories); if (remote_files != null && remote_files.Length > 0) { total_count++; ArrayUtil.RemoveDuplicationElements(ref remote_files); foreach (var item in remote_files) { string pure_path = item.Substring(remote_path_len, item.Length - remote_path_len); string target_path = Path.Combine(binary_path_temp_remote, pure_path); XDirectory.CreateIfNotExists(Path.GetDirectoryName(target_path)); File.Copy(item, target_path); } } } } else { string group_path = VFSEditorUtil.Get_ExtensionGroupFolderPath_InSourcePackages(platform_name, branch.ExtensionGroupName); int group_path_len = group_path.Length + 1; string[] group_files = Directory.GetFiles(group_path, "*.*", SearchOption.AllDirectories); if (group_files != null && group_files.Length > 0) { total_count++; ArrayUtil.RemoveDuplicationElements(ref group_files); foreach (var item in group_files) { string pure_path = item.Substring(group_path_len, item.Length - group_path_len); string target_path = Path.Combine(binary_path_temp, pure_path); XDirectory.CreateIfNotExists(Path.GetDirectoryName(target_path)); File.Copy(item, target_path); } } } long zip_counter = 0; int zip_counter_t = 0; //打包 string zip_file_path = Path.Combine(binary_path, VFSEditorConst.VFS_VERSION_AssetsBinary_Zip_Name); ZipUtil.ZipDirectory(binary_path_temp, zip_file_path, fileName => { if (log || dialog) { zip_counter++; if (total_count > 100) { zip_counter_t++; if (zip_counter_t >= 20) { zip_counter_t = 0; if (log) { Debug.Log($" Create Zip: {zip_counter}/{total_count}"); } if (dialog) { EditorUtility.DisplayProgressBar("Create Zip", $"{zip_counter}/{total_count}\n{fileName}", zip_counter / total_count); } } } else { if (log) { Debug.Log($" Create Zip: {zip_counter}/{total_count} : {fileName}"); } if (dialog) { EditorUtility.DisplayProgressBar("Create Zip", $"{zip_counter}/{total_count}\n{fileName}", zip_counter / total_count); } } } }); if (isMainPackage) { string zip_file_path_remote = Path.Combine(binary_path, VFSEditorConst.VFS_VERSION_AssetsBinary_REMOTE_Zip_Name); zip_counter = 0; zip_counter_t = 0; ZipUtil.ZipDirectory(binary_path_temp_remote, zip_file_path_remote, fileName => { if (log || dialog) { zip_counter++; if (total_count > 100) { zip_counter_t++; if (zip_counter_t >= 20) { zip_counter_t = 0; if (log) { Debug.Log($" Create Zip: {zip_counter}/{total_count}"); } if (dialog) { EditorUtility.DisplayProgressBar("Create Zip", $"{zip_counter}/{total_count}\n{fileName}", zip_counter / total_count); } } } else { if (log) { Debug.Log($" Create Zip: {zip_counter}/{total_count} : {fileName}"); } if (dialog) { EditorUtility.DisplayProgressBar("Create Zip", $"{zip_counter}/{total_count}\n{fileName}", zip_counter / total_count); } } } }); } if (dialog) { EditorUtility.ClearProgressBar(); //上面这个应该是同步方法,不会有时间错乱。(吧 } //删除temp XDirectory.DeleteIfExists(binary_path_temp); XDirectory.DeleteIfExists(binary_path_temp_remote); } catch (Exception e) { flag_process_error = true; XDirectory.DeleteIfExists(binary_path); throw e; } } if (!flag_process_error) { //登记到索引 var vr = new VersionRecord() { versionCode = versionCode, versionName = versionName, desc = versionDesc, build_id = build_id }; //记录版本 branch.AddVersion(ref vr); //保存版本索引 SaveBranchFile(ref branch); } } } }
/// <summary> /// 复制到StreamingAssets /// </summary> /// <param name="packages_root_path">Packages根目录(有vfs_root,vfs_data之类的那个目录)</param> /// <param name="platform_name">平台名</param> public static void CopyToStreamingAssets(string packages_root_path, string platform_name, bool clearOtherPlatformFiles = false, bool OnlyMainPackage = false) { VFSEditorUtil.InitVFSFoldersInStreamingAssets(platform_name, clearOtherPlatformFiles); var stream_root_path = Path.Combine(Application.streamingAssetsPath, VFSConst.VFS_STREAMINGASSETS_PATH); var project_vfs_root_path = Path.Combine(packages_root_path, VFSConst.VFS_FOLDER_MAIN); if (Directory.Exists(project_vfs_root_path)) { string target_vfs_root = Path.Combine(stream_root_path, platform_name, VFSConst.VFS_FOLDER_MAIN); XDirectory.DeleteIfExists(target_vfs_root); XDirectory.CopyDir(project_vfs_root_path, target_vfs_root); } if (!OnlyMainPackage) { var project_vfs_extension_group = Path.Combine(packages_root_path, VFSConst.VFS_FOLDER_EXTENSION); if (Directory.Exists(project_vfs_extension_group)) { string target_vfs_extension = Path.Combine(stream_root_path, platform_name, VFSConst.VFS_FOLDER_EXTENSION); XDirectory.DeleteIfExists(target_vfs_extension); XDirectory.CopyDir(project_vfs_extension_group, target_vfs_extension); } } //Data目录处理---------------------------------------------------------- //assetBundle hash var main_package_assetbundle_hash_files_folder_path = VFSUtil.GetMainPackageAssetBundleHashFilesRootPath(packages_root_path); if (Directory.Exists(main_package_assetbundle_hash_files_folder_path)) { string target_path = VFSUtil.GetMainPackageAssetBundleHashFilesRootPath(Path.Combine(stream_root_path, platform_name)); XDirectory.DeleteIfExists(target_path); XDirectory.CopyDir(main_package_assetbundle_hash_files_folder_path, target_path); } //manifest var main_package_manifest_file_folder_path = VFSUtil.GetMainPackage_AssetBundleManifests_Folder(packages_root_path); if (Directory.Exists(main_package_manifest_file_folder_path)) { string target_path = VFSUtil.GetMainPackage_AssetBundleManifests_Folder(Path.Combine(stream_root_path, platform_name)); XDirectory.DeleteIfExists(target_path); XDirectory.CopyDir(main_package_manifest_file_folder_path, target_path); } //build info var main_package_build_info = VFSUtil.GetMainPackage_BuildInfo_Path(packages_root_path); if (File.Exists(main_package_build_info)) { string target_path = VFSUtil.GetMainPackage_BuildInfo_Path(Path.Combine(stream_root_path, platform_name)); XFile.DeleteIfExists(target_path); XDirectory.CreateIfNotExists(Path.GetDirectoryName(target_path)); File.Copy(main_package_build_info, target_path); } //package version info var main_package_version_info = VFSUtil.GetMainPackage_VersionInfo_Path(packages_root_path); if (File.Exists(main_package_version_info)) { string target_path = VFSUtil.GetMainPackage_VersionInfo_Path(Path.Combine(stream_root_path, platform_name)); XFile.DeleteIfExists(target_path); XDirectory.CreateIfNotExists(Path.GetDirectoryName(target_path)); File.Copy(main_package_version_info, target_path); } //vfs config var vfs_config_path = VFSUtil.GetVFSConfigFilePath_InPackages(packages_root_path); if (File.Exists(vfs_config_path)) { string target_path = VFSUtil.GetVFSConfigFilePath_InPackages(Path.Combine(stream_root_path, platform_name)); XFile.DeleteIfExists(target_path); XDirectory.CreateIfNotExists(Path.GetDirectoryName(target_path)); File.Copy(vfs_config_path, target_path, true); } }
/// <summary> /// 把构建好的AssetBundle文件根据组进行复制分类 /// </summary> /// <param name="group"></param> /// <param name="build_ab_path"></param> /// <param name="target_root_path"></param> /// <returns></returns> private bool CopyAssetBundleFilesByGroup(VFSEditorGroup group, string build_ab_path, string target_root_path) { bool moved = false; int counter = 0; int counter_t = 0; int total_len = mDict_Group_AssetBundleNames[group.GroupName].Count; if (EnableTipsGUI && total_len > 100) { EditorUtility.DisplayProgressBar("Classifying files", $"Classifying assetbundle files by group \"{group.GroupName}\"", 0.5f); } foreach (var assetbundle_name in mDict_Group_AssetBundleNames[group.GroupName]) { if (EnableTipsGUI) { counter++; counter_t++; if (total_len > 100) { if (counter_t > 50) { counter_t = 0; EditorUtility.DisplayProgressBar("Classifying files", $"Classifying assetbundle files by group \"{group.GroupName}\"\n{counter} / {total_len}", counter / total_len); } } } string assetbundle_path = Path.Combine(build_ab_path, assetbundle_name); if (File.Exists(assetbundle_path)) { string target_path = Path.Combine(target_root_path, assetbundle_name); XFile.DeleteIfExists(target_path); XDirectory.CreateIfNotExists(Path.GetDirectoryName(target_path)); File.Copy(assetbundle_path, target_path); if (mUsePipeline) { FileStream fileStream = new FileStream(target_path, FileMode.Open, FileAccess.ReadWrite); void InvokePipline(BuilderPipelineContext ctx) { if (ctx.Handler != null) { bool b = ctx.Handler.BeforeAssetBundleFileSavedByGroup(ref group, assetbundle_name, ref fileStream); if (b && ctx.Next != null) { InvokePipline(ctx.Next); } } } if (mPipeline.First != null) { InvokePipline(mPipeline.First); } fileStream.Close(); fileStream.Dispose(); } moved = true; } } if (EnableTipsGUI) { EditorUtility.ClearProgressBar(); } return(moved); }
/// <summary> /// /// </summary> /// <param name="root_path">存放一系列VFS目录的根目录</param> /// <param name="build_root_path">Unity的Build结果输出目录</param> public void HandleVFSFiles(string root_path, string build_root_path, XRuntimePlatform platform) { mEditorBuildInfo = new EditorBuildInfo(); List <VFSEditorGroup> groups = VFSManagerEditor.GetGroups(); string remote_files_root_path = Path.Combine(root_path, VFSEditorConst.PROJECT_VFS_FILE_FOLDER_REMOTE); string local_files_root_path = Path.Combine(root_path, VFSEditorConst.PROJECT_VFS_FILES_FOLDER_MAIN); string source_packages_extension_root_folder = Path.Combine(root_path, VFSEditorConst.PROJECT_VFS_FILES_FOLDER_EXTENSION); XDirectory.DeleteIfExists(remote_files_root_path, true); XDirectory.DeleteIfExists(local_files_root_path, true); XDirectory.DeleteIfExists(source_packages_extension_root_folder, true); foreach (var group in groups) { //扩展组的判断 if (group.ExtensionGroup) { #region 处理扩展组 string extension_group_root_path = Path.Combine(source_packages_extension_root_folder, group.GroupName.ToLower()); bool moved = CopyAssetBundleFilesByGroup(group, build_root_path, extension_group_root_path); if (moved) { //manifest group.MakeVFSManifest(root_path, mDict_Group_AssetBundleNames[group.GroupName], ref mAssetBundleManifest); //给独立的组生成一份hash group.MakeAssetBundleFilesHash(root_path, extension_group_root_path, mDict_Group_AssetBundleNames[group.GroupName]); SaveExtensionGroupInfo(extension_group_root_path, group.GroupName, platform, group.ExtensionGroup_MainPackageVersionLimit, Config.AssetBundleFileExtension); //保存Options group.SaveGroupOptionFile(root_path); } #endregion //登记 if (curProfile.IsDisabledGroup(group.GroupName)) { mEditorBuildInfo.list_disable_extension.Add(group.GroupName); } else { mEditorBuildInfo.list_total_extension.Add(group.GroupName); if (group.HandleMode == GroupHandleMode.LocalOrRemote) { if (curProfile.TryGetGroupLocation(group.GroupName, out var location)) { if (location == ProfileRecord.E_GroupAssetsLocation.Local) { mEditorBuildInfo.list_extension_local.Add(group.GroupName); } else if (location == ProfileRecord.E_GroupAssetsLocation.Remote) { mEditorBuildInfo.list_extension_remote.Add(group.GroupName); } } else { mEditorBuildInfo.list_extension_local.Add(group.GroupName); } } else if (group.HandleMode == GroupHandleMode.RemoteOnly) { mEditorBuildInfo.list_extension_remote.Add(group.GroupName); } else { mEditorBuildInfo.list_extension_local.Add(group.GroupName); } } } else { bool moveToRemote = false; bool moveToLocal = false; if (group.HandleMode == GroupHandleMode.LocalOrRemote) { if (curProfile.TryGetGroupLocation(group.GroupName, out var location)) { if (location == ProfileRecord.E_GroupAssetsLocation.Remote) { moveToRemote = true; } else { moveToLocal = true; } } else { moveToLocal = true; } } else if (group.HandleMode == GroupHandleMode.RemoteOnly) { moveToRemote = true; } else if (group.HandleMode == GroupHandleMode.LocalOnly || group.HandleMode == GroupHandleMode.LocalAndUpdatable) { moveToLocal = true; } //登记 mEditorBuildInfo.list_total_main_package.Add(group.GroupName); if (moveToRemote) { //登记 mEditorBuildInfo.list_main_package_remote.Add(group.GroupName); XDirectory.CreateIfNotExists(remote_files_root_path); CopyAssetBundleFilesByGroup(group, build_root_path, remote_files_root_path); //上一步copy的时候,开发者自定义的pipeline可以改变文件,所以制作assetbundle的hash信息的时候,必须使用上一步处理后的结果 group.MakeAssetBundleFilesHash(root_path, remote_files_root_path, mDict_Group_AssetBundleNames[group.GroupName]); } else if (moveToLocal) { //登记 mEditorBuildInfo.list_main_package_local.Add(group.GroupName); XDirectory.CreateIfNotExists(local_files_root_path); CopyAssetBundleFilesByGroup(group, build_root_path, local_files_root_path); //上一步copy的时候,开发者自定义的pipeline可以改变文件,所以制作assetbundle的hash信息的时候,必须使用上一步处理后的结果 group.MakeAssetBundleFilesHash(root_path, local_files_root_path, mDict_Group_AssetBundleNames[group.GroupName]); } group.MakeVFSManifest(root_path, mDict_Group_AssetBundleNames[group.GroupName], ref mAssetBundleManifest); } } }
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 }