using System.Collections.Generic; using YooAsset.Editor; using YooAsset; using GFGGame; using UnityEditor; using System.IO; using cfg.GfgCfg; using UnityEngine; namespace GFGEditor { public class PresetAssetHelper { public static void CopyPresetAssets() { // 等待资源构建流程完成 //...... //选择清单文件 string selectedFile = EditorUtility.OpenFilePanel("Select a file", "", ""); if (string.IsNullOrEmpty(selectedFile)) { return; } int t = selectedFile.LastIndexOf("/"); string dirPath = selectedFile.Substring(0, t); //生成预制资源列表 AssetBundlePreloadFiles assetBundlePreloadFiles = AssetBundlePreloadFiles.GetData(); List preloadFiles = new List(); preloadFiles.AddRange(assetBundlePreloadFiles.PreloadFiles); //SqliteController.Instance.Init(false, null); // List dataArray = CommonDataManager.Tables.TblStoryDialogCfg.DataList; // foreach (var cfg in dataArray) // { // if (!string.IsNullOrEmpty(cfg.BgRes)) // { // var resPath = ResPathUtil.GetSceneBgPath(cfg.BgRes); // preloadFiles.Add(resPath); // } // } // 加载构建成功的资源清单对象 byte[] manifestBytes = FileUtility.ReadAllBytes(selectedFile); PackageManifest manifest = ManifestTools.DeserializeFromBinary(manifestBytes); // 查找所有需要打进首包资源的依赖AB HashSet bundles = new HashSet(); foreach (var assetPath in preloadFiles) { TryAdd(assetPath, manifest, bundles); } // List dressUpItemlist = // CommonDataManager.Tables.TblItemCfg.GetGroup1ByItemType(ConstItemType.DRESS_UP); // foreach (var dressUpCfg in dressUpItemlist) // { // if (dressUpCfg.LoadType > 0) // { // string assetPath = ResPathUtil.GetDressUpLayerSpriteResPath(dressUpCfg, 1); // TryAdd(assetPath, manifest, bundles); // assetPath = ResPathUtil.GetDressUpLayerSpriteResPath(dressUpCfg, 2); // TryAdd(assetPath, manifest, bundles); // assetPath = ResPathUtil.GetDressUpLayerSpriteResPath(dressUpCfg, 3); // TryAdd(assetPath, manifest, bundles); // assetPath = ResPathUtil.GetDressUpLayerAnimationResPath(dressUpCfg, 1); // TryAdd(assetPath, manifest, bundles); // assetPath = ResPathUtil.GetDressUpLayerAnimationResPath(dressUpCfg, 2); // TryAdd(assetPath, manifest, bundles); // assetPath = ResPathUtil.GetDressUpLayerAnimationResPath(dressUpCfg, 3); // TryAdd(assetPath, manifest, bundles); // assetPath = ResPathUtil.GetDressUpLayerEffectResPath(dressUpCfg, 1, false); // TryAdd(assetPath, manifest, bundles); // assetPath = ResPathUtil.GetDressUpLayerEffectResPath(dressUpCfg, 2, false); // TryAdd(assetPath, manifest, bundles); // assetPath = ResPathUtil.GetDressUpLayerEffectResPath(dressUpCfg, 3, false); // TryAdd(assetPath, manifest, bundles); // TryAdd(assetPath, manifest, bundles); // assetPath = ResPathUtil.GetDressUpLayerEffectResPath(dressUpCfg, 1, true); // TryAdd(assetPath, manifest, bundles); // assetPath = ResPathUtil.GetDressUpLayerEffectResPath(dressUpCfg, 2, true); // TryAdd(assetPath, manifest, bundles); // assetPath = ResPathUtil.GetDressUpLayerEffectResPath(dressUpCfg, 3, true); // TryAdd(assetPath, manifest, bundles); // } // } string root = $"{AssetBundleBuilderHelper.GetDefaultStreamingAssetsRoot()}/{VersionController.DefaultPackage}"; //清空 EditorTools.ClearFolder(root); // 拷贝指定动态加载文件 foreach (var packageBundle in bundles) { string destPath = $"{root}/{packageBundle.FileName}"; //...... //拷贝文件 string sourcePath = $"{dirPath}/{packageBundle.FileName}"; EditorTools.CopyFile(sourcePath, destPath, true); //Debug.Log($"sourcePath { sourcePath}"); Debug.Log($"destPath {destPath}"); } //拷贝指定标签的文件 string[] tags = { "preload" }; foreach (var packageBundle in manifest.BundleList) { if (packageBundle.HasTag(tags) == false) continue; string sourcePath = $"{dirPath}/{packageBundle.FileName}"; string destPath = $"{root}/{packageBundle.FileName}"; EditorTools.CopyFile(sourcePath, destPath, true); Debug.Log($"destPath {destPath}"); } } private static void TryAdd(string assetPath, PackageManifest manifest, HashSet bundles) { if (manifest.TryGetPackageAsset(assetPath, out PackageAsset packageAsset)) { var packageBundle = manifest.BundleList[packageAsset.BundleID]; if (bundles.Contains(packageBundle) == false) { bundles.Add(packageBundle); Debug.Log($"preload assetPath {assetPath}"); } } } } }