| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129 | 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.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<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}");                }            }        }    }}
 |