12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- using System.Collections.Generic;
- using YooAsset.Editor;
- using YooAsset;
- using GFGGame;
- using UnityEditor;
- using System.IO;
- using UnityEngine;
- namespace GFGEditor
- {
- public class PreloadAssetHelper
- {
- public static void CopyPreloadAssets()
- {
- // 等待资源构建流程完成
- //......
- string selectedFile = EditorUtility.OpenFilePanel("Select a file", "", "");
- if(string.IsNullOrEmpty(selectedFile))
- {
- return;
- }
- int t = selectedFile.LastIndexOf("/");
- string dirPath = selectedFile.Substring(0, t);
- // 加载构建成功的资源清单对象
- byte[] manifestBytes = FileUtility.ReadAllBytes(selectedFile);
- PackageManifest manifest = ManifestTools.DeserializeFromBinary(manifestBytes);
- // 查找所有需要打进首包资源的依赖AB
- HashSet<PackageBundle> bundles = new HashSet<PackageBundle>();
- AssetBundlePreloadFiles assetBundlePreloadFiles = AssetBundlePreloadFiles.GetData();
- foreach (var assetPath in assetBundlePreloadFiles.PreloadFiles)
- {
- if (manifest.TryGetPackageAsset(assetPath, out PackageAsset packageAsset))
- {
- var packageBundle = manifest.BundleList[packageAsset.BundleID];
- if (bundles.Contains(packageBundle) == false)
- bundles.Add(packageBundle);
- }
- }
- // 拷贝所有首包文件
- string root = $"{AssetBundleBuilderHelper.GetDefaultStreamingAssetsRoot()}/{VersionController.DefaultPackage}";
- foreach (var packageBundle in bundles)
- {
- string destPath = $"{root}/{packageBundle.FileName}";
- //...... //拷贝文件
- string sourcePath = $"{dirPath}/{packageBundle.FileName}";
- File.Copy(sourcePath, destPath, true);
- Debug.Log($"sourcePath { sourcePath}");
- Debug.Log($"destPath { destPath}");
- }
- }
- }
- }
|