protected override void OnRender() { if (IsEnable) { if (GUILayout.Button("Del Config", GUILayout.ExpandWidth(false))) { IsEnable = false; string filePath = Path.Combine(EAssetBundleToolUtil.GetDiskPath(ModuleRoot.RootPath), "_.config.txt"); File.Delete(filePath); File.Delete(filePath + ".meta"); ModuleRoot.RemoveAllComponentsOfChild(); AssetDatabase.Refresh(); } } else { if (GUILayout.Button("Create Config", GUILayout.ExpandWidth(false))) { IsEnable = true; string filePath = Path.Combine(EAssetBundleToolUtil.GetDiskPath(ModuleRoot.RootPath), "_.config.txt"); File.WriteAllText(filePath, ""); foreach (var v in ModuleRoot.Tree) { v.SetComponent(new EGUIComponentFolderItem(v)); } AssetDatabase.Refresh(); } } }
/// <summary> /// 重新载入文件树结构的数据 /// </summary> void ReloadFolderData() { foreach (var v in TreeRoot.Tree) { string fPath = EAssetBundleToolUtil.GetDiskPath(v.RootPath + "/_.config.txt"); bool isEnable = File.Exists(fPath); v.SetComponent(new EGUIComponentFolderModule(isEnable, v)); if (isEnable) { v.GetComponent <EGUIComponentFolderModule>().SetConfigMap(EAssetBundleToolUtil.StringToConfigMap(File.ReadAllText(fPath))); } } }
/// <summary> /// 点击存储将模块下的配置属性写入本地文件_.config.txt /// </summary> void OnClickSave() { foreach (var v in TreeRoot.Tree) { string fPath = EAssetBundleToolUtil.GetDiskPath(v.RootPath + "/_.config.txt"); var component = v.GetComponent <EGUIComponentFolderModule>(); Dictionary <string, List <string> > outConfigMap; if (component.TryGetConfigMap(out outConfigMap)) { File.WriteAllText(fPath, EAssetBundleToolUtil.ConfigMapToString(outConfigMap)); } } AssetDatabase.Refresh(); }
/// <summary> /// 清除被选中模块AssetBundle的名称 /// </summary> void OnClearAssetBundleName() { var foldersObject = FolderList.GetChooseFolder(); foreach (var v in foldersObject) { EAssetBundleToolUtil.ClearAssetBundleName(v.RelativePath); System.IO.File.Delete(EAssetBundleToolUtil.GetDiskPath(v.RelativePath + "/manifest.txt")); System.IO.File.Delete(EAssetBundleToolUtil.GetDiskPath(v.RelativePath + "/manifest.txt.meta")); OnClearModuleName(v.FolderName, v.RelativePath); } AssetDatabase.Refresh(); Debug.Log("Clear AssetBundle Name Complete!"); }
/// <summary> /// 点击输出AssetBundle文件 /// </summary> void OnClickOutputAssetBundle() { //> 确定目标平台 BuildTarget selection = EditorUserBuildSettings.activeBuildTarget; if (BuildTargetDropdown.Visible) { selection = (BuildTarget)BuildTargetDropdown.Value; } //> 确定输出模块 var foldersObject = FolderList.GetChooseFolder(); if (foldersObject.Count == 0) { Debug.LogError("Invalid build:Chose at least one module."); } AssetDatabase.RemoveUnusedAssetBundleNames(); var allAssetBundleNames = AssetDatabase.GetAllAssetBundleNames(); var outputPath1 = EAssetBundleToolUtil.GetDiskPath("AssetBundlePool/" + selection.ToString()); var outputPath2 = EAssetBundleToolUtil.GetDiskPath(Config.AssetBundleOutput + "/" + selection.ToString()); if (!Directory.Exists(outputPath1)) { Directory.CreateDirectory(outputPath1); } if (!Directory.Exists(outputPath2)) { Directory.CreateDirectory(outputPath2); } List <FileVersionInfo> versionList = new List <FileVersionInfo>(); //> 构建AB文件到资源池 foreach (var v in foldersObject) { var names = EAssetBundleToolUtil.GetAssetBundleNamesByModule(allAssetBundleNames, v.FolderName.ToLower()); var buildMap = EAssetBundleToolUtil.GetBuildMapByAssetBundleNames(names); if (buildMap.Count == 0) { continue; } string finalOutputPath1 = outputPath1; string finalOutputPath2 = outputPath2; if (Config.IsModuleStructure) { finalOutputPath1 += "/" + v.FolderName.ToLower(); finalOutputPath2 += "/" + v.FolderName.ToLower(); if (!Directory.Exists(finalOutputPath1)) { Directory.CreateDirectory(finalOutputPath1); } if (!Directory.Exists(finalOutputPath2)) { Directory.CreateDirectory(finalOutputPath2); } } BuildPipeline.BuildAssetBundles(finalOutputPath1, buildMap.ToArray(), BuildAssetBundleOptions.StrictMode, selection); //> 拷贝AB文件到输出目录 List <FileVersionInfo> moduleVersion = new List <FileVersionInfo>(); foreach (var f in names) { if (File.Exists(finalOutputPath1 + "/" + f)) { File.Copy(finalOutputPath1 + "/" + f, finalOutputPath2 + "/" + f, true); //> 创建版本文件信息 moduleVersion.Add(TiyVersionListCreator.GetVersionInfoByFile(outputPath2, finalOutputPath2 + "/" + f, v.FolderName.ToLower())); } else { Debug.LogErrorFormat("File is missing:{0}", finalOutputPath1 + "/" + f); } } if (Config.IsCreateVersionList) { if (Config.IsModuleStructureForVersion) { string versionFilePath = ""; if (Config.IsModuleStructure) { versionFilePath = outputPath2 + "/" + v.FolderName.ToLower() + "/" + "version.list"; } else { versionFilePath = outputPath2 + "/" + v.FolderName.ToLower() + "." + "version.list"; } TiyVersionListCreator.CreateVersionListByTemplate(moduleVersion, Config.FullVersionListTemplateFile, versionFilePath); } else { versionList.AddRange(moduleVersion); } } } if (Config.IsCreateVersionList && versionList.Count > 0) { TiyVersionListCreator.CreateVersionListByTemplate(versionList, Config.FullVersionListTemplateFile, outputPath2 + "/version.list"); } System.Diagnostics.Process.Start(outputPath2); Debug.Log("Build Complete!"); GUIUtility.ExitGUI(); }