|
@@ -0,0 +1,111 @@
|
|
|
|
+using System.Collections.Generic;
|
|
|
|
+using YooAsset.Editor;
|
|
|
|
+using YooAsset;
|
|
|
|
+using GFGGame;
|
|
|
|
+using UnityEditor;
|
|
|
|
+using System.IO;
|
|
|
|
+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<string> preloadFiles = new List<string>();
|
|
|
|
+ preloadFiles.AddRange(assetBundlePreloadFiles.PreloadFiles);
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ SqliteController.Instance.Init(false, null);
|
|
|
|
+ StoryDialogCfg[] dataArray = StoryDialogCfgArray.Instance.dataArray;
|
|
|
|
+ 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<PackageBundle> bundles = new HashSet<PackageBundle>();
|
|
|
|
+ foreach (var assetPath in preloadFiles)
|
|
|
|
+ {
|
|
|
|
+ TryAdd(assetPath, manifest, bundles);
|
|
|
|
+ }
|
|
|
|
+ List<ItemCfg> dressUpItemlist = ItemCfgArray.Instance.GetCfgsByitemType(ConstItemType.DRESS_UP);
|
|
|
|
+ foreach(var dressUpCfg in dressUpItemlist)
|
|
|
|
+ {
|
|
|
|
+ if(dressUpCfg.loadType > 0)
|
|
|
|
+ {
|
|
|
|
+ string assetPath = ResPathUtil.GetDressUpItemLayerRes(dressUpCfg, 1);
|
|
|
|
+ TryAdd(assetPath, manifest, bundles);
|
|
|
|
+ assetPath = ResPathUtil.GetDressUpItemLayerRes(dressUpCfg, 2);
|
|
|
|
+ TryAdd(assetPath, manifest, bundles);
|
|
|
|
+ assetPath = ResPathUtil.GetDressUpItemLayerRes(dressUpCfg, 3);
|
|
|
|
+ TryAdd(assetPath, manifest, bundles);
|
|
|
|
+ assetPath = ResPathUtil.GetDressUpAnimationPath(dressUpCfg.res);
|
|
|
|
+ TryAdd(assetPath, manifest, bundles);
|
|
|
|
+ assetPath = ResPathUtil.GetDressUpEffectPath(dressUpCfg.res);
|
|
|
|
+ TryAdd(assetPath, manifest, bundles);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ string root = $"{AssetBundleBuilderHelper.GetDefaultStreamingAssetsRoot()}/{VersionController.DefaultPackage}";
|
|
|
|
+ // 拷贝指定动态加载文件
|
|
|
|
+ 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<PackageBundle> 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}");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+}
|