From 67d09d95fa4dc703e6014c9db99d0f6dc3a09ed2 Mon Sep 17 00:00:00 2001 From: hevinci Date: Sat, 11 Mar 2023 00:06:40 +0800 Subject: [PATCH] update runtime code MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 代码里移除了Patch敏感字。 --- Assets/YooAsset/Runtime/AssetReference.cs | 4 +- .../Loader/AssetBundleFileLoader.cs | 2 +- .../AssetSystem/Loader/RawBundleFileLoader.cs | 2 +- .../AssetSystem/Loader/RawBundleWebLoader.cs | 2 +- .../Runtime/CacheSystem/CacheSystem.cs | 2 +- .../ClearUnusedCacheFilesOperation.cs | 4 +- .../YooAsset/Runtime/InitializeParameters.cs | 2 +- .../YooAsset/Runtime/PatchSystem/AssetInfo.cs | 26 +-- .../Runtime/PatchSystem/BundleInfo.cs | 14 +- .../Runtime/PatchSystem/ManifestTools.cs | 193 ++++++++++++++++++ ...estTools.cs.meta => ManifestTools.cs.meta} | 0 .../Operations/DownloaderOperation.cs | 20 +- .../Operations/InitializationOperation.cs | 8 +- .../Internal/DeserializeManifestOperation.cs | 88 ++++---- .../Internal/LoadBuildinManifestOperation.cs | 2 +- .../Internal/LoadCacheManifestOperation.cs | 2 +- .../Internal/LoadEditorManifestOperation.cs | 2 +- ...tion.cs => PreDownloadContentOperation.cs} | 98 +++++---- ...ta => PreDownloadContentOperation.cs.meta} | 0 .../UpdatePackageManifestOperation.cs | 2 +- .../{PatchAsset.cs => PackageAsset.cs} | 2 +- ...atchAsset.cs.meta => PackageAsset.cs.meta} | 0 .../{PatchBundle.cs => PackageBundle.cs} | 10 +- ...chBundle.cs.meta => PackageBundle.cs.meta} | 0 .../{PatchManifest.cs => PackageManifest.cs} | 78 +++---- ...nifest.cs.meta => PackageManifest.cs.meta} | 0 .../Runtime/PatchSystem/PatchManifestTools.cs | 193 ------------------ .../PlayMode/EditorSimulateModeHelper.cs | 4 +- .../PlayMode/EditorSimulateModeImpl.cs | 40 ++-- .../PatchSystem/PlayMode/HostPlayModeImpl.cs | 164 +++++++-------- .../PlayMode/OfflinePlayModeImpl.cs | 52 ++--- .../{AssetsPackage.cs => ResourcePackage.cs} | 114 ++++++++--- ...ackage.cs.meta => ResourcePackage.cs.meta} | 0 .../Services/Internal/IPlayModeServices.cs | 20 +- .../Runtime/Settings/YooAssetSettings.cs | 8 +- .../Runtime/Settings/YooAssetSettingsData.cs | 8 +- Assets/YooAsset/Runtime/YooAssets.cs | 22 +- Assets/YooAsset/Runtime/YooAssetsExtension.cs | 84 +++++--- 38 files changed, 692 insertions(+), 580 deletions(-) create mode 100644 Assets/YooAsset/Runtime/PatchSystem/ManifestTools.cs rename Assets/YooAsset/Runtime/PatchSystem/{PatchManifestTools.cs.meta => ManifestTools.cs.meta} (100%) rename Assets/YooAsset/Runtime/PatchSystem/Operations/{PreDownloadPackageOperation.cs => PreDownloadContentOperation.cs} (52%) rename Assets/YooAsset/Runtime/PatchSystem/Operations/{PreDownloadPackageOperation.cs.meta => PreDownloadContentOperation.cs.meta} (100%) rename Assets/YooAsset/Runtime/PatchSystem/{PatchAsset.cs => PackageAsset.cs} (96%) rename Assets/YooAsset/Runtime/PatchSystem/{PatchAsset.cs.meta => PackageAsset.cs.meta} (100%) rename Assets/YooAsset/Runtime/PatchSystem/{PatchBundle.cs => PackageBundle.cs} (94%) rename Assets/YooAsset/Runtime/PatchSystem/{PatchBundle.cs.meta => PackageBundle.cs.meta} (100%) rename Assets/YooAsset/Runtime/PatchSystem/{PatchManifest.cs => PackageManifest.cs} (75%) rename Assets/YooAsset/Runtime/PatchSystem/{PatchManifest.cs.meta => PackageManifest.cs.meta} (100%) delete mode 100644 Assets/YooAsset/Runtime/PatchSystem/PatchManifestTools.cs rename Assets/YooAsset/Runtime/{AssetsPackage.cs => ResourcePackage.cs} (81%) rename Assets/YooAsset/Runtime/{AssetsPackage.cs.meta => ResourcePackage.cs.meta} (100%) diff --git a/Assets/YooAsset/Runtime/AssetReference.cs b/Assets/YooAsset/Runtime/AssetReference.cs index ac67f57..2ed11d0 100644 --- a/Assets/YooAsset/Runtime/AssetReference.cs +++ b/Assets/YooAsset/Runtime/AssetReference.cs @@ -1,8 +1,8 @@ - +using UnityEngine; + namespace YooAsset { public class AssetReference { - } } \ No newline at end of file diff --git a/Assets/YooAsset/Runtime/AssetSystem/Loader/AssetBundleFileLoader.cs b/Assets/YooAsset/Runtime/AssetSystem/Loader/AssetBundleFileLoader.cs index 02aa373..b113421 100644 --- a/Assets/YooAsset/Runtime/AssetSystem/Loader/AssetBundleFileLoader.cs +++ b/Assets/YooAsset/Runtime/AssetSystem/Loader/AssetBundleFileLoader.cs @@ -110,7 +110,7 @@ namespace YooAsset if (_steps == ESteps.Unpack) { int failedTryAgain = 1; - var bundleInfo = PatchManifestTools.GetUnpackInfo(MainBundleInfo.Bundle); + var bundleInfo = ManifestTools.GetUnpackInfo(MainBundleInfo.Bundle); _unpacker = DownloadSystem.BeginDownload(bundleInfo, failedTryAgain); _steps = ESteps.CheckUnpack; } diff --git a/Assets/YooAsset/Runtime/AssetSystem/Loader/RawBundleFileLoader.cs b/Assets/YooAsset/Runtime/AssetSystem/Loader/RawBundleFileLoader.cs index 923e72c..4aa615f 100644 --- a/Assets/YooAsset/Runtime/AssetSystem/Loader/RawBundleFileLoader.cs +++ b/Assets/YooAsset/Runtime/AssetSystem/Loader/RawBundleFileLoader.cs @@ -92,7 +92,7 @@ namespace YooAsset if (_steps == ESteps.Unpack) { int failedTryAgain = 1; - var bundleInfo = PatchManifestTools.GetUnpackInfo(MainBundleInfo.Bundle); + var bundleInfo = ManifestTools.GetUnpackInfo(MainBundleInfo.Bundle); _unpacker = DownloadSystem.BeginDownload(bundleInfo, failedTryAgain); _steps = ESteps.CheckUnpack; } diff --git a/Assets/YooAsset/Runtime/AssetSystem/Loader/RawBundleWebLoader.cs b/Assets/YooAsset/Runtime/AssetSystem/Loader/RawBundleWebLoader.cs index 6459873..c98565a 100644 --- a/Assets/YooAsset/Runtime/AssetSystem/Loader/RawBundleWebLoader.cs +++ b/Assets/YooAsset/Runtime/AssetSystem/Loader/RawBundleWebLoader.cs @@ -90,7 +90,7 @@ namespace YooAsset if (_steps == ESteps.Website) { int failedTryAgain = 1; - var bundleInfo = PatchManifestTools.GetUnpackInfo(MainBundleInfo.Bundle); + var bundleInfo = ManifestTools.GetUnpackInfo(MainBundleInfo.Bundle); _website = DownloadSystem.BeginDownload(bundleInfo, failedTryAgain); _steps = ESteps.CheckWebsite; } diff --git a/Assets/YooAsset/Runtime/CacheSystem/CacheSystem.cs b/Assets/YooAsset/Runtime/CacheSystem/CacheSystem.cs index 02107ff..94310ae 100644 --- a/Assets/YooAsset/Runtime/CacheSystem/CacheSystem.cs +++ b/Assets/YooAsset/Runtime/CacheSystem/CacheSystem.cs @@ -133,7 +133,7 @@ namespace YooAsset /// /// 获取未被使用的缓存文件 /// - public static List GetUnusedCacheGUIDs(AssetsPackage package) + public static List GetUnusedCacheGUIDs(ResourcePackage package) { var cache = GetOrCreateCache(package.PackageName); var keys = cache.GetAllKeys(); diff --git a/Assets/YooAsset/Runtime/CacheSystem/Operations/ClearUnusedCacheFilesOperation.cs b/Assets/YooAsset/Runtime/CacheSystem/Operations/ClearUnusedCacheFilesOperation.cs index 1fe3bdd..c5a7e8d 100644 --- a/Assets/YooAsset/Runtime/CacheSystem/Operations/ClearUnusedCacheFilesOperation.cs +++ b/Assets/YooAsset/Runtime/CacheSystem/Operations/ClearUnusedCacheFilesOperation.cs @@ -17,12 +17,12 @@ namespace YooAsset Done, } - private readonly AssetsPackage _package; + private readonly ResourcePackage _package; private List _unusedCacheGUIDs; private int _unusedFileTotalCount = 0; private ESteps _steps = ESteps.None; - internal ClearUnusedCacheFilesOperation(AssetsPackage package) + internal ClearUnusedCacheFilesOperation(ResourcePackage package) { _package = package; } diff --git a/Assets/YooAsset/Runtime/InitializeParameters.cs b/Assets/YooAsset/Runtime/InitializeParameters.cs index 8417830..d543ca0 100644 --- a/Assets/YooAsset/Runtime/InitializeParameters.cs +++ b/Assets/YooAsset/Runtime/InitializeParameters.cs @@ -53,7 +53,7 @@ namespace YooAsset /// /// 用于模拟运行的资源清单路径 /// - public string SimulatePatchManifestPath = string.Empty; + public string SimulateManifestFilePath = string.Empty; } /// diff --git a/Assets/YooAsset/Runtime/PatchSystem/AssetInfo.cs b/Assets/YooAsset/Runtime/PatchSystem/AssetInfo.cs index 215b66f..9a5411d 100644 --- a/Assets/YooAsset/Runtime/PatchSystem/AssetInfo.cs +++ b/Assets/YooAsset/Runtime/PatchSystem/AssetInfo.cs @@ -3,7 +3,7 @@ namespace YooAsset { public class AssetInfo { - private readonly PatchAsset _patchAsset; + private readonly PackageAsset _packageAsset; private string _providerGUID; /// @@ -42,7 +42,7 @@ namespace YooAsset { get { - return _patchAsset == null; + return _packageAsset == null; } } @@ -53,9 +53,9 @@ namespace YooAsset { get { - if (_patchAsset == null) + if (_packageAsset == null) return string.Empty; - return _patchAsset.Address; + return _packageAsset.Address; } } @@ -66,9 +66,9 @@ namespace YooAsset { get { - if (_patchAsset == null) + if (_packageAsset == null) return string.Empty; - return _patchAsset.AssetPath; + return _packageAsset.AssetPath; } } @@ -77,30 +77,30 @@ namespace YooAsset { // 注意:禁止从外部创建该类 } - internal AssetInfo(PatchAsset patchAsset, System.Type assetType) + internal AssetInfo(PackageAsset packageAsset, System.Type assetType) { - if (patchAsset == null) + if (packageAsset == null) throw new System.Exception("Should never get here !"); _providerGUID = string.Empty; - _patchAsset = patchAsset; + _packageAsset = packageAsset; AssetType = assetType; Error = string.Empty; } - internal AssetInfo(PatchAsset patchAsset) + internal AssetInfo(PackageAsset packageAsset) { - if (patchAsset == null) + if (packageAsset == null) throw new System.Exception("Should never get here !"); _providerGUID = string.Empty; - _patchAsset = patchAsset; + _packageAsset = packageAsset; AssetType = null; Error = string.Empty; } internal AssetInfo(string error) { _providerGUID = string.Empty; - _patchAsset = null; + _packageAsset = null; AssetType = null; Error = error; } diff --git a/Assets/YooAsset/Runtime/PatchSystem/BundleInfo.cs b/Assets/YooAsset/Runtime/PatchSystem/BundleInfo.cs index 18a5c57..18e9007 100644 --- a/Assets/YooAsset/Runtime/PatchSystem/BundleInfo.cs +++ b/Assets/YooAsset/Runtime/PatchSystem/BundleInfo.cs @@ -12,7 +12,7 @@ namespace YooAsset LoadFromEditor, } - public readonly PatchBundle Bundle; + public readonly PackageBundle Bundle; public readonly ELoadMode LoadMode; /// @@ -34,25 +34,25 @@ namespace YooAsset private BundleInfo() { } - public BundleInfo(PatchBundle patchBundle, ELoadMode loadMode, string mainURL, string fallbackURL) + public BundleInfo(PackageBundle bundle, ELoadMode loadMode, string mainURL, string fallbackURL) { - Bundle = patchBundle; + Bundle = bundle; LoadMode = loadMode; RemoteMainURL = mainURL; RemoteFallbackURL = fallbackURL; EditorAssetPath = string.Empty; } - public BundleInfo(PatchBundle patchBundle, ELoadMode loadMode, string editorAssetPath) + public BundleInfo(PackageBundle bundle, ELoadMode loadMode, string editorAssetPath) { - Bundle = patchBundle; + Bundle = bundle; LoadMode = loadMode; RemoteMainURL = string.Empty; RemoteFallbackURL = string.Empty; EditorAssetPath = editorAssetPath; } - public BundleInfo(PatchBundle patchBundle, ELoadMode loadMode) + public BundleInfo(PackageBundle bundle, ELoadMode loadMode) { - Bundle = patchBundle; + Bundle = bundle; LoadMode = loadMode; RemoteMainURL = string.Empty; RemoteFallbackURL = string.Empty; diff --git a/Assets/YooAsset/Runtime/PatchSystem/ManifestTools.cs b/Assets/YooAsset/Runtime/PatchSystem/ManifestTools.cs new file mode 100644 index 0000000..70ccc60 --- /dev/null +++ b/Assets/YooAsset/Runtime/PatchSystem/ManifestTools.cs @@ -0,0 +1,193 @@ +using System; +using System.IO; +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +namespace YooAsset +{ + internal static class ManifestTools + { + +#if UNITY_EDITOR + /// + /// 序列化(JSON文件) + /// + public static void SerializeToJson(string savePath, PackageManifest manifest) + { + string json = JsonUtility.ToJson(manifest, true); + FileUtility.CreateFile(savePath, json); + } + + /// + /// 序列化(二进制文件) + /// + public static void SerializeToBinary(string savePath, PackageManifest manifest) + { + using (FileStream fs = new FileStream(savePath, FileMode.Create)) + { + // 创建缓存器 + BufferWriter buffer = new BufferWriter(YooAssetSettings.ManifestFileMaxSize); + + // 写入文件标记 + buffer.WriteUInt32(YooAssetSettings.ManifestFileSign); + + // 写入文件版本 + buffer.WriteUTF8(manifest.FileVersion); + + // 写入文件头信息 + buffer.WriteBool(manifest.EnableAddressable); + buffer.WriteInt32(manifest.OutputNameStyle); + buffer.WriteUTF8(manifest.PackageName); + buffer.WriteUTF8(manifest.PackageVersion); + + // 写入资源列表 + buffer.WriteInt32(manifest.AssetList.Count); + for (int i = 0; i < manifest.AssetList.Count; i++) + { + var packageAsset = manifest.AssetList[i]; + buffer.WriteUTF8(packageAsset.Address); + buffer.WriteUTF8(packageAsset.AssetPath); + buffer.WriteUTF8Array(packageAsset.AssetTags); + buffer.WriteInt32(packageAsset.BundleID); + buffer.WriteInt32Array(packageAsset.DependIDs); + } + + // 写入资源包列表 + buffer.WriteInt32(manifest.BundleList.Count); + for (int i = 0; i < manifest.BundleList.Count; i++) + { + var packageBundle = manifest.BundleList[i]; + buffer.WriteUTF8(packageBundle.BundleName); + buffer.WriteUTF8(packageBundle.FileHash); + buffer.WriteUTF8(packageBundle.FileCRC); + buffer.WriteInt64(packageBundle.FileSize); + buffer.WriteBool(packageBundle.IsRawFile); + buffer.WriteByte(packageBundle.LoadMethod); + buffer.WriteUTF8Array(packageBundle.Tags); + buffer.WriteInt32Array(packageBundle.ReferenceIDs); + } + + // 写入文件流 + buffer.WriteToStream(fs); + fs.Flush(); + } + } + + /// + /// 反序列化(二进制文件) + /// + public static PackageManifest DeserializeFromBinary(byte[] binaryData) + { + // 创建缓存器 + BufferReader buffer = new BufferReader(binaryData); + + // 读取文件标记 + uint fileSign = buffer.ReadUInt32(); + if (fileSign != YooAssetSettings.ManifestFileSign) + throw new Exception("Invalid manifest file !"); + + // 读取文件版本 + string fileVersion = buffer.ReadUTF8(); + if (fileVersion != YooAssetSettings.ManifestFileVersion) + throw new Exception($"The manifest file version are not compatible : {fileVersion} != {YooAssetSettings.ManifestFileVersion}"); + + PackageManifest manifest = new PackageManifest(); + { + // 读取文件头信息 + manifest.FileVersion = fileVersion; + manifest.EnableAddressable = buffer.ReadBool(); + manifest.OutputNameStyle = buffer.ReadInt32(); + manifest.PackageName = buffer.ReadUTF8(); + manifest.PackageVersion = buffer.ReadUTF8(); + + // 读取资源列表 + int packageAssetCount = buffer.ReadInt32(); + manifest.AssetList = new List(packageAssetCount); + for (int i = 0; i < packageAssetCount; i++) + { + var packageAsset = new PackageAsset(); + packageAsset.Address = buffer.ReadUTF8(); + packageAsset.AssetPath = buffer.ReadUTF8(); + packageAsset.AssetTags = buffer.ReadUTF8Array(); + packageAsset.BundleID = buffer.ReadInt32(); + packageAsset.DependIDs = buffer.ReadInt32Array(); + manifest.AssetList.Add(packageAsset); + } + + // 读取资源包列表 + int packageBundleCount = buffer.ReadInt32(); + manifest.BundleList = new List(packageBundleCount); + for (int i = 0; i < packageBundleCount; i++) + { + var packageBundle = new PackageBundle(); + packageBundle.BundleName = buffer.ReadUTF8(); + packageBundle.FileHash = buffer.ReadUTF8(); + packageBundle.FileCRC = buffer.ReadUTF8(); + packageBundle.FileSize = buffer.ReadInt64(); + packageBundle.IsRawFile = buffer.ReadBool(); + packageBundle.LoadMethod = buffer.ReadByte(); + packageBundle.Tags = buffer.ReadUTF8Array(); + packageBundle.ReferenceIDs = buffer.ReadInt32Array(); + manifest.BundleList.Add(packageBundle); + } + } + + // BundleDic + manifest.BundleDic = new Dictionary(manifest.BundleList.Count); + foreach (var packageBundle in manifest.BundleList) + { + packageBundle.ParseBundle(manifest.PackageName, manifest.OutputNameStyle); + manifest.BundleDic.Add(packageBundle.BundleName, packageBundle); + } + + // AssetDic + manifest.AssetDic = new Dictionary(manifest.AssetList.Count); + foreach (var packageAsset in manifest.AssetList) + { + // 注意:我们不允许原始路径存在重名 + string assetPath = packageAsset.AssetPath; + if (manifest.AssetDic.ContainsKey(assetPath)) + throw new Exception($"AssetPath have existed : {assetPath}"); + else + manifest.AssetDic.Add(assetPath, packageAsset); + } + + return manifest; + } +#endif + + public static string GetRemoteBundleFileExtension(string bundleName) + { + string fileExtension = Path.GetExtension(bundleName); + return fileExtension; + } + public static string GetRemoteBundleFileName(int nameStyle, string bundleName, string fileExtension, string fileHash) + { + if (nameStyle == 1) //HashName + { + return StringUtility.Format("{0}{1}", fileHash, fileExtension); + } + else if (nameStyle == 4) //BundleName_HashName + { + string fileName = bundleName.Remove(bundleName.LastIndexOf('.')); + return StringUtility.Format("{0}_{1}{2}", fileName, fileHash, fileExtension); + } + else + { + throw new NotImplementedException($"Invalid name style : {nameStyle}"); + } + } + + /// + /// 获取解压BundleInfo + /// + public static BundleInfo GetUnpackInfo(PackageBundle packageBundle) + { + // 注意:我们把流加载路径指定为远端下载地址 + string streamingPath = PathHelper.ConvertToWWWPath(packageBundle.StreamingFilePath); + BundleInfo bundleInfo = new BundleInfo(packageBundle, BundleInfo.ELoadMode.LoadFromStreaming, streamingPath, streamingPath); + return bundleInfo; + } + } +} \ No newline at end of file diff --git a/Assets/YooAsset/Runtime/PatchSystem/PatchManifestTools.cs.meta b/Assets/YooAsset/Runtime/PatchSystem/ManifestTools.cs.meta similarity index 100% rename from Assets/YooAsset/Runtime/PatchSystem/PatchManifestTools.cs.meta rename to Assets/YooAsset/Runtime/PatchSystem/ManifestTools.cs.meta diff --git a/Assets/YooAsset/Runtime/PatchSystem/Operations/DownloaderOperation.cs b/Assets/YooAsset/Runtime/PatchSystem/Operations/DownloaderOperation.cs index c3edded..352c617 100644 --- a/Assets/YooAsset/Runtime/PatchSystem/Operations/DownloaderOperation.cs +++ b/Assets/YooAsset/Runtime/PatchSystem/Operations/DownloaderOperation.cs @@ -94,9 +94,9 @@ namespace YooAsset if (downloadList != null) { TotalDownloadCount = downloadList.Count; - foreach (var patchBundle in downloadList) + foreach (var packageBundle in downloadList) { - TotalDownloadBytes += patchBundle.Bundle.FileSize; + TotalDownloadBytes += packageBundle.Bundle.FileSize; } } } @@ -249,9 +249,9 @@ namespace YooAsset } } - public sealed class PatchDownloaderOperation : DownloaderOperation + public sealed class ResourceDownloaderOperation : DownloaderOperation { - internal PatchDownloaderOperation(List downloadList, int downloadingMaxNumber, int failedTryAgain, int timeout) + internal ResourceDownloaderOperation(List downloadList, int downloadingMaxNumber, int failedTryAgain, int timeout) : base(downloadList, downloadingMaxNumber, failedTryAgain, timeout) { } @@ -259,16 +259,16 @@ namespace YooAsset /// /// 创建空的下载器 /// - internal static PatchDownloaderOperation CreateEmptyDownloader(int downloadingMaxNumber, int failedTryAgain, int timeout) + internal static ResourceDownloaderOperation CreateEmptyDownloader(int downloadingMaxNumber, int failedTryAgain, int timeout) { List downloadList = new List(); - var operation = new PatchDownloaderOperation(downloadList, downloadingMaxNumber, failedTryAgain, timeout); + var operation = new ResourceDownloaderOperation(downloadList, downloadingMaxNumber, failedTryAgain, timeout); return operation; } } - public sealed class PatchUnpackerOperation : DownloaderOperation + public sealed class ResourceUnpackerOperation : DownloaderOperation { - internal PatchUnpackerOperation(List downloadList, int downloadingMaxNumber, int failedTryAgain, int timeout) + internal ResourceUnpackerOperation(List downloadList, int downloadingMaxNumber, int failedTryAgain, int timeout) : base(downloadList, downloadingMaxNumber, failedTryAgain, timeout) { } @@ -276,10 +276,10 @@ namespace YooAsset /// /// 创建空的解压器 /// - internal static PatchUnpackerOperation CreateEmptyUnpacker(int upackingMaxNumber, int failedTryAgain, int timeout) + internal static ResourceUnpackerOperation CreateEmptyUnpacker(int upackingMaxNumber, int failedTryAgain, int timeout) { List downloadList = new List(); - var operation = new PatchUnpackerOperation(downloadList, upackingMaxNumber, failedTryAgain, int.MaxValue); + var operation = new ResourceUnpackerOperation(downloadList, upackingMaxNumber, failedTryAgain, int.MaxValue); return operation; } } diff --git a/Assets/YooAsset/Runtime/PatchSystem/Operations/InitializationOperation.cs b/Assets/YooAsset/Runtime/PatchSystem/Operations/InitializationOperation.cs index ba63581..8683be6 100644 --- a/Assets/YooAsset/Runtime/PatchSystem/Operations/InitializationOperation.cs +++ b/Assets/YooAsset/Runtime/PatchSystem/Operations/InitializationOperation.cs @@ -26,14 +26,14 @@ namespace YooAsset } private readonly EditorSimulateModeImpl _impl; - private readonly string _simulateManifestPath; + private readonly string _simulateManifestFilePath; private LoadEditorManifestOperation _loadEditorManifestOp; private ESteps _steps = ESteps.None; - internal EditorSimulateModeInitializationOperation(EditorSimulateModeImpl impl, string simulateManifestPath) + internal EditorSimulateModeInitializationOperation(EditorSimulateModeImpl impl, string simulateManifestFilePath) { _impl = impl; - _simulateManifestPath = simulateManifestPath; + _simulateManifestFilePath = simulateManifestFilePath; } internal override void Start() { @@ -45,7 +45,7 @@ namespace YooAsset { if (_loadEditorManifestOp == null) { - _loadEditorManifestOp = new LoadEditorManifestOperation(_simulateManifestPath); + _loadEditorManifestOp = new LoadEditorManifestOperation(_simulateManifestFilePath); OperationSystem.StartOperation(_loadEditorManifestOp); } diff --git a/Assets/YooAsset/Runtime/PatchSystem/Operations/Internal/DeserializeManifestOperation.cs b/Assets/YooAsset/Runtime/PatchSystem/Operations/Internal/DeserializeManifestOperation.cs index 8a2d3de..973246c 100644 --- a/Assets/YooAsset/Runtime/PatchSystem/Operations/Internal/DeserializeManifestOperation.cs +++ b/Assets/YooAsset/Runtime/PatchSystem/Operations/Internal/DeserializeManifestOperation.cs @@ -18,15 +18,15 @@ namespace YooAsset } private readonly BufferReader _buffer; - private int _patchAssetCount; - private int _patchBundleCount; + private int _packageAssetCount; + private int _packageBundleCount; private int _progressTotalValue; private ESteps _steps = ESteps.None; /// /// 解析的清单实例 /// - public PatchManifest Manifest { private set; get; } + public PackageManifest Manifest { private set; get; } public DeserializeManifestOperation(byte[] binaryData) { @@ -55,7 +55,7 @@ namespace YooAsset // 读取文件标记 uint fileSign = _buffer.ReadUInt32(); - if (fileSign != YooAssetSettings.PatchManifestFileSign) + if (fileSign != YooAssetSettings.ManifestFileSign) { _steps = ESteps.Done; Status = EOperationStatus.Failed; @@ -65,16 +65,16 @@ namespace YooAsset // 读取文件版本 string fileVersion = _buffer.ReadUTF8(); - if (fileVersion != YooAssetSettings.PatchManifestFileVersion) + if (fileVersion != YooAssetSettings.ManifestFileVersion) { _steps = ESteps.Done; Status = EOperationStatus.Failed; - Error = $"The manifest file version are not compatible : {fileVersion} != {YooAssetSettings.PatchManifestFileVersion}"; + Error = $"The manifest file version are not compatible : {fileVersion} != {YooAssetSettings.ManifestFileVersion}"; return; } // 读取文件头信息 - Manifest = new PatchManifest(); + Manifest = new PackageManifest(); Manifest.FileVersion = fileVersion; Manifest.EnableAddressable = _buffer.ReadBool(); Manifest.OutputNameStyle = _buffer.ReadInt32(); @@ -86,38 +86,38 @@ namespace YooAsset if (_steps == ESteps.PrepareAssetList) { - _patchAssetCount = _buffer.ReadInt32(); - Manifest.AssetList = new List(_patchAssetCount); - Manifest.AssetDic = new Dictionary(_patchAssetCount); - _progressTotalValue = _patchAssetCount; + _packageAssetCount = _buffer.ReadInt32(); + Manifest.AssetList = new List(_packageAssetCount); + Manifest.AssetDic = new Dictionary(_packageAssetCount); + _progressTotalValue = _packageAssetCount; _steps = ESteps.DeserializeAssetList; } if (_steps == ESteps.DeserializeAssetList) { - while (_patchAssetCount > 0) + while (_packageAssetCount > 0) { - var patchAsset = new PatchAsset(); - patchAsset.Address = _buffer.ReadUTF8(); - patchAsset.AssetPath = _buffer.ReadUTF8(); - patchAsset.AssetTags = _buffer.ReadUTF8Array(); - patchAsset.BundleID = _buffer.ReadInt32(); - patchAsset.DependIDs = _buffer.ReadInt32Array(); - Manifest.AssetList.Add(patchAsset); + var packageAsset = new PackageAsset(); + packageAsset.Address = _buffer.ReadUTF8(); + packageAsset.AssetPath = _buffer.ReadUTF8(); + packageAsset.AssetTags = _buffer.ReadUTF8Array(); + packageAsset.BundleID = _buffer.ReadInt32(); + packageAsset.DependIDs = _buffer.ReadInt32Array(); + Manifest.AssetList.Add(packageAsset); // 注意:我们不允许原始路径存在重名 - string assetPath = patchAsset.AssetPath; + string assetPath = packageAsset.AssetPath; if (Manifest.AssetDic.ContainsKey(assetPath)) throw new System.Exception($"AssetPath have existed : {assetPath}"); else - Manifest.AssetDic.Add(assetPath, patchAsset); + Manifest.AssetDic.Add(assetPath, packageAsset); - _patchAssetCount--; - Progress = 1f - _patchAssetCount / _progressTotalValue; + _packageAssetCount--; + Progress = 1f - _packageAssetCount / _progressTotalValue; if (OperationSystem.IsBusy) break; } - if (_patchAssetCount <= 0) + if (_packageAssetCount <= 0) { _steps = ESteps.PrepareBundleList; } @@ -125,37 +125,37 @@ namespace YooAsset if (_steps == ESteps.PrepareBundleList) { - _patchBundleCount = _buffer.ReadInt32(); - Manifest.BundleList = new List(_patchBundleCount); - Manifest.BundleDic = new Dictionary(_patchBundleCount); - _progressTotalValue = _patchBundleCount; + _packageBundleCount = _buffer.ReadInt32(); + Manifest.BundleList = new List(_packageBundleCount); + Manifest.BundleDic = new Dictionary(_packageBundleCount); + _progressTotalValue = _packageBundleCount; _steps = ESteps.DeserializeBundleList; } if (_steps == ESteps.DeserializeBundleList) { - while (_patchBundleCount > 0) + while (_packageBundleCount > 0) { - var patchBundle = new PatchBundle(); - patchBundle.BundleName = _buffer.ReadUTF8(); - patchBundle.FileHash = _buffer.ReadUTF8(); - patchBundle.FileCRC = _buffer.ReadUTF8(); - patchBundle.FileSize = _buffer.ReadInt64(); - patchBundle.IsRawFile = _buffer.ReadBool(); - patchBundle.LoadMethod = _buffer.ReadByte(); - patchBundle.Tags = _buffer.ReadUTF8Array(); - patchBundle.ReferenceIDs = _buffer.ReadInt32Array(); - Manifest.BundleList.Add(patchBundle); + var packageBundle = new PackageBundle(); + packageBundle.BundleName = _buffer.ReadUTF8(); + packageBundle.FileHash = _buffer.ReadUTF8(); + packageBundle.FileCRC = _buffer.ReadUTF8(); + packageBundle.FileSize = _buffer.ReadInt64(); + packageBundle.IsRawFile = _buffer.ReadBool(); + packageBundle.LoadMethod = _buffer.ReadByte(); + packageBundle.Tags = _buffer.ReadUTF8Array(); + packageBundle.ReferenceIDs = _buffer.ReadInt32Array(); + Manifest.BundleList.Add(packageBundle); - patchBundle.ParseBundle(Manifest.PackageName, Manifest.OutputNameStyle); - Manifest.BundleDic.Add(patchBundle.BundleName, patchBundle); + packageBundle.ParseBundle(Manifest.PackageName, Manifest.OutputNameStyle); + Manifest.BundleDic.Add(packageBundle.BundleName, packageBundle); - _patchBundleCount--; - Progress = 1f - _patchBundleCount / _progressTotalValue; + _packageBundleCount--; + Progress = 1f - _packageBundleCount / _progressTotalValue; if (OperationSystem.IsBusy) break; } - if (_patchBundleCount <= 0) + if (_packageBundleCount <= 0) { _steps = ESteps.Done; Status = EOperationStatus.Succeed; diff --git a/Assets/YooAsset/Runtime/PatchSystem/Operations/Internal/LoadBuildinManifestOperation.cs b/Assets/YooAsset/Runtime/PatchSystem/Operations/Internal/LoadBuildinManifestOperation.cs index 10e183d..3791262 100644 --- a/Assets/YooAsset/Runtime/PatchSystem/Operations/Internal/LoadBuildinManifestOperation.cs +++ b/Assets/YooAsset/Runtime/PatchSystem/Operations/Internal/LoadBuildinManifestOperation.cs @@ -20,7 +20,7 @@ namespace YooAsset /// /// 加载的清单实例 /// - public PatchManifest Manifest { private set; get; } + public PackageManifest Manifest { private set; get; } public LoadBuildinManifestOperation(string buildinPackageName, string buildinPackageVersion) diff --git a/Assets/YooAsset/Runtime/PatchSystem/Operations/Internal/LoadCacheManifestOperation.cs b/Assets/YooAsset/Runtime/PatchSystem/Operations/Internal/LoadCacheManifestOperation.cs index 93f651f..708d395 100644 --- a/Assets/YooAsset/Runtime/PatchSystem/Operations/Internal/LoadCacheManifestOperation.cs +++ b/Assets/YooAsset/Runtime/PatchSystem/Operations/Internal/LoadCacheManifestOperation.cs @@ -24,7 +24,7 @@ namespace YooAsset /// /// 加载的清单实例 /// - public PatchManifest Manifest { private set; get; } + public PackageManifest Manifest { private set; get; } public LoadCacheManifestOperation(string packageName, string packageVersion) diff --git a/Assets/YooAsset/Runtime/PatchSystem/Operations/Internal/LoadEditorManifestOperation.cs b/Assets/YooAsset/Runtime/PatchSystem/Operations/Internal/LoadEditorManifestOperation.cs index 1fd210d..5fe071f 100644 --- a/Assets/YooAsset/Runtime/PatchSystem/Operations/Internal/LoadEditorManifestOperation.cs +++ b/Assets/YooAsset/Runtime/PatchSystem/Operations/Internal/LoadEditorManifestOperation.cs @@ -19,7 +19,7 @@ namespace YooAsset /// /// 加载的清单实例 /// - public PatchManifest Manifest { private set; get; } + public PackageManifest Manifest { private set; get; } public LoadEditorManifestOperation(string manifestFilePath) diff --git a/Assets/YooAsset/Runtime/PatchSystem/Operations/PreDownloadPackageOperation.cs b/Assets/YooAsset/Runtime/PatchSystem/Operations/PreDownloadContentOperation.cs similarity index 52% rename from Assets/YooAsset/Runtime/PatchSystem/Operations/PreDownloadPackageOperation.cs rename to Assets/YooAsset/Runtime/PatchSystem/Operations/PreDownloadContentOperation.cs index fe3034c..c4dfbdc 100644 --- a/Assets/YooAsset/Runtime/PatchSystem/Operations/PreDownloadPackageOperation.cs +++ b/Assets/YooAsset/Runtime/PatchSystem/Operations/PreDownloadContentOperation.cs @@ -4,57 +4,69 @@ using System.Collections.Generic; namespace YooAsset { - public abstract class PreDownloadPackageOperation : AsyncOperationBase + public abstract class PreDownloadContentOperation : AsyncOperationBase { /// - /// 创建补丁下载器,用于下载更新指定资源版本所有的资源包文件 + /// 创建资源下载器,用于下载当前资源版本所有的资源包文件 /// /// 同时下载的最大文件数 /// 下载失败的重试次数 /// 超时时间 - public virtual PatchDownloaderOperation CreatePatchDownloader(int downloadingMaxNumber, int failedTryAgain, int timeout = 60) + public virtual ResourceDownloaderOperation CreateResourceDownloader(int downloadingMaxNumber, int failedTryAgain, int timeout = 60) { - return PatchDownloaderOperation.CreateEmptyDownloader(downloadingMaxNumber, failedTryAgain, timeout); + return ResourceDownloaderOperation.CreateEmptyDownloader(downloadingMaxNumber, failedTryAgain, timeout); } /// - /// 创建补丁下载器,用于下载更新资源标签指定的资源包文件 + /// 创建资源下载器,用于下载指定的资源标签关联的资源包文件 /// /// 资源标签 /// 同时下载的最大文件数 /// 下载失败的重试次数 /// 超时时间 - public virtual PatchDownloaderOperation CreatePatchDownloader(string tag, int downloadingMaxNumber, int failedTryAgain, int timeout = 60) + public virtual ResourceDownloaderOperation CreateResourceDownloader(string tag, int downloadingMaxNumber, int failedTryAgain, int timeout = 60) { - return PatchDownloaderOperation.CreateEmptyDownloader(downloadingMaxNumber, failedTryAgain, timeout); + return ResourceDownloaderOperation.CreateEmptyDownloader(downloadingMaxNumber, failedTryAgain, timeout); } /// - /// 创建补丁下载器,用于下载更新资源标签指定的资源包文件 + /// 创建资源下载器,用于下载指定的资源标签列表关联的资源包文件 /// /// 资源标签列表 /// 同时下载的最大文件数 /// 下载失败的重试次数 /// 超时时间 - public virtual PatchDownloaderOperation CreatePatchDownloader(string[] tags, int downloadingMaxNumber, int failedTryAgain, int timeout = 60) + public virtual ResourceDownloaderOperation CreateResourceDownloader(string[] tags, int downloadingMaxNumber, int failedTryAgain, int timeout = 60) { - return PatchDownloaderOperation.CreateEmptyDownloader(downloadingMaxNumber, failedTryAgain, timeout); + return ResourceDownloaderOperation.CreateEmptyDownloader(downloadingMaxNumber, failedTryAgain, timeout); } /// - /// 创建补丁下载器,用于下载更新指定的资源列表依赖的资源包文件 + /// 创建资源下载器,用于下载指定的资源依赖的资源包文件 /// - /// 资源定位列表 + /// 资源定位地址 /// 同时下载的最大文件数 /// 下载失败的重试次数 /// 超时时间 - public virtual PatchDownloaderOperation CreateBundleDownloader(string[] locations, int downloadingMaxNumber, int failedTryAgain, int timeout = 60) + public virtual ResourceDownloaderOperation CreateBundleDownloader(string location, int downloadingMaxNumber, int failedTryAgain, int timeout = 60) { - return PatchDownloaderOperation.CreateEmptyDownloader(downloadingMaxNumber, failedTryAgain, timeout); + return ResourceDownloaderOperation.CreateEmptyDownloader(downloadingMaxNumber, failedTryAgain, timeout); + } + + /// + /// 创建资源下载器,用于下载指定的资源列表依赖的资源包文件 + /// + /// 资源定位地址列表 + /// 同时下载的最大文件数 + /// 下载失败的重试次数 + /// 超时时间 + public virtual ResourceDownloaderOperation CreateBundleDownloader(string[] locations, int downloadingMaxNumber, int failedTryAgain, int timeout = 60) + { + return ResourceDownloaderOperation.CreateEmptyDownloader(downloadingMaxNumber, failedTryAgain, timeout); } } - public class EditorPlayModePreDownloadPackageOperation : PreDownloadPackageOperation + internal class EditorPlayModePreDownloadContentOperation : PreDownloadContentOperation { internal override void Start() { @@ -64,7 +76,7 @@ namespace YooAsset { } } - public class OfflinePlayModePreDownloadPackageOperation : PreDownloadPackageOperation + internal class OfflinePlayModePreDownloadContentOperation : PreDownloadContentOperation { internal override void Start() { @@ -74,7 +86,7 @@ namespace YooAsset { } } - public class HostPlayModePreDownloadPackageOperation : PreDownloadPackageOperation + internal class HostPlayModePreDownloadContentOperation : PreDownloadContentOperation { private enum ESteps { @@ -94,11 +106,11 @@ namespace YooAsset private LoadCacheManifestOperation _tryLoadCacheManifestOp; private LoadCacheManifestOperation _loadCacheManifestOp; private DownloadManifestOperation _downloadManifestOp; - private PatchManifest _manifest; + private PackageManifest _manifest; private ESteps _steps = ESteps.None; - internal HostPlayModePreDownloadPackageOperation(HostPlayModeImpl impl, string packageName, string packageVersion, int timeout) + internal HostPlayModePreDownloadContentOperation(HostPlayModeImpl impl, string packageName, string packageVersion, int timeout) { _impl = impl; _packageName = packageName; @@ -202,48 +214,64 @@ namespace YooAsset } } - public override PatchDownloaderOperation CreatePatchDownloader(int downloadingMaxNumber, int failedTryAgain, int timeout = 60) + public override ResourceDownloaderOperation CreateResourceDownloader(int downloadingMaxNumber, int failedTryAgain, int timeout = 60) { if (Status != EOperationStatus.Succeed) { - YooLogger.Warning($"{nameof(PreDownloadPackageOperation)} status is not succeed !"); - return PatchDownloaderOperation.CreateEmptyDownloader(downloadingMaxNumber, failedTryAgain, timeout); + YooLogger.Warning($"{nameof(PreDownloadContentOperation)} status is not succeed !"); + return ResourceDownloaderOperation.CreateEmptyDownloader(downloadingMaxNumber, failedTryAgain, timeout); } List downloadList = _impl.GetDownloadListByAll(_manifest); - var operation = new PatchDownloaderOperation(downloadList, downloadingMaxNumber, failedTryAgain, timeout); + var operation = new ResourceDownloaderOperation(downloadList, downloadingMaxNumber, failedTryAgain, timeout); return operation; } - public override PatchDownloaderOperation CreatePatchDownloader(string tag, int downloadingMaxNumber, int failedTryAgain, int timeout = 60) + public override ResourceDownloaderOperation CreateResourceDownloader(string tag, int downloadingMaxNumber, int failedTryAgain, int timeout = 60) { if (Status != EOperationStatus.Succeed) { - YooLogger.Warning($"{nameof(PreDownloadPackageOperation)} status is not succeed !"); - return PatchDownloaderOperation.CreateEmptyDownloader(downloadingMaxNumber, failedTryAgain, timeout); + YooLogger.Warning($"{nameof(PreDownloadContentOperation)} status is not succeed !"); + return ResourceDownloaderOperation.CreateEmptyDownloader(downloadingMaxNumber, failedTryAgain, timeout); } List downloadList = _impl.GetDownloadListByTags(_manifest, new string[] { tag }); - var operation = new PatchDownloaderOperation(downloadList, downloadingMaxNumber, failedTryAgain, timeout); + var operation = new ResourceDownloaderOperation(downloadList, downloadingMaxNumber, failedTryAgain, timeout); return operation; } - public override PatchDownloaderOperation CreatePatchDownloader(string[] tags, int downloadingMaxNumber, int failedTryAgain, int timeout = 60) + public override ResourceDownloaderOperation CreateResourceDownloader(string[] tags, int downloadingMaxNumber, int failedTryAgain, int timeout = 60) { if (Status != EOperationStatus.Succeed) { - YooLogger.Warning($"{nameof(PreDownloadPackageOperation)} status is not succeed !"); - return PatchDownloaderOperation.CreateEmptyDownloader(downloadingMaxNumber, failedTryAgain, timeout); + YooLogger.Warning($"{nameof(PreDownloadContentOperation)} status is not succeed !"); + return ResourceDownloaderOperation.CreateEmptyDownloader(downloadingMaxNumber, failedTryAgain, timeout); } List downloadList = _impl.GetDownloadListByTags(_manifest, tags); - var operation = new PatchDownloaderOperation(downloadList, downloadingMaxNumber, failedTryAgain, timeout); + var operation = new ResourceDownloaderOperation(downloadList, downloadingMaxNumber, failedTryAgain, timeout); return operation; } - public override PatchDownloaderOperation CreateBundleDownloader(string[] locations, int downloadingMaxNumber, int failedTryAgain, int timeout = 60) + public override ResourceDownloaderOperation CreateBundleDownloader(string location, int downloadingMaxNumber, int failedTryAgain, int timeout = 60) { if (Status != EOperationStatus.Succeed) { - YooLogger.Warning($"{nameof(PreDownloadPackageOperation)} status is not succeed !"); - return PatchDownloaderOperation.CreateEmptyDownloader(downloadingMaxNumber, failedTryAgain, timeout); + YooLogger.Warning($"{nameof(PreDownloadContentOperation)} status is not succeed !"); + return ResourceDownloaderOperation.CreateEmptyDownloader(downloadingMaxNumber, failedTryAgain, timeout); + } + + List assetInfos = new List(); + var assetInfo = _manifest.ConvertLocationToAssetInfo(location, null); + assetInfos.Add(assetInfo); + + List downloadList = _impl.GetDownloadListByPaths(_manifest, assetInfos.ToArray()); + var operation = new ResourceDownloaderOperation(downloadList, downloadingMaxNumber, failedTryAgain, timeout); + return operation; + } + public override ResourceDownloaderOperation CreateBundleDownloader(string[] locations, int downloadingMaxNumber, int failedTryAgain, int timeout = 60) + { + if (Status != EOperationStatus.Succeed) + { + YooLogger.Warning($"{nameof(PreDownloadContentOperation)} status is not succeed !"); + return ResourceDownloaderOperation.CreateEmptyDownloader(downloadingMaxNumber, failedTryAgain, timeout); } List assetInfos = new List(locations.Length); @@ -254,7 +282,7 @@ namespace YooAsset } List downloadList = _impl.GetDownloadListByPaths(_manifest, assetInfos.ToArray()); - var operation = new PatchDownloaderOperation(downloadList, downloadingMaxNumber, failedTryAgain, timeout); + var operation = new ResourceDownloaderOperation(downloadList, downloadingMaxNumber, failedTryAgain, timeout); return operation; } } diff --git a/Assets/YooAsset/Runtime/PatchSystem/Operations/PreDownloadPackageOperation.cs.meta b/Assets/YooAsset/Runtime/PatchSystem/Operations/PreDownloadContentOperation.cs.meta similarity index 100% rename from Assets/YooAsset/Runtime/PatchSystem/Operations/PreDownloadPackageOperation.cs.meta rename to Assets/YooAsset/Runtime/PatchSystem/Operations/PreDownloadContentOperation.cs.meta diff --git a/Assets/YooAsset/Runtime/PatchSystem/Operations/UpdatePackageManifestOperation.cs b/Assets/YooAsset/Runtime/PatchSystem/Operations/UpdatePackageManifestOperation.cs index 4704eea..8e6d061 100644 --- a/Assets/YooAsset/Runtime/PatchSystem/Operations/UpdatePackageManifestOperation.cs +++ b/Assets/YooAsset/Runtime/PatchSystem/Operations/UpdatePackageManifestOperation.cs @@ -5,7 +5,7 @@ using System.Collections.Generic; namespace YooAsset { /// - /// 向远端请求并更新补丁清单 + /// 向远端请求并更新清单 /// public abstract class UpdatePackageManifestOperation : AsyncOperationBase { diff --git a/Assets/YooAsset/Runtime/PatchSystem/PatchAsset.cs b/Assets/YooAsset/Runtime/PatchSystem/PackageAsset.cs similarity index 96% rename from Assets/YooAsset/Runtime/PatchSystem/PatchAsset.cs rename to Assets/YooAsset/Runtime/PatchSystem/PackageAsset.cs index 6cd35d9..3ba70fb 100644 --- a/Assets/YooAsset/Runtime/PatchSystem/PatchAsset.cs +++ b/Assets/YooAsset/Runtime/PatchSystem/PackageAsset.cs @@ -4,7 +4,7 @@ using System.Linq; namespace YooAsset { [Serializable] - internal class PatchAsset + internal class PackageAsset { /// /// 可寻址地址 diff --git a/Assets/YooAsset/Runtime/PatchSystem/PatchAsset.cs.meta b/Assets/YooAsset/Runtime/PatchSystem/PackageAsset.cs.meta similarity index 100% rename from Assets/YooAsset/Runtime/PatchSystem/PatchAsset.cs.meta rename to Assets/YooAsset/Runtime/PatchSystem/PackageAsset.cs.meta diff --git a/Assets/YooAsset/Runtime/PatchSystem/PatchBundle.cs b/Assets/YooAsset/Runtime/PatchSystem/PackageBundle.cs similarity index 94% rename from Assets/YooAsset/Runtime/PatchSystem/PatchBundle.cs rename to Assets/YooAsset/Runtime/PatchSystem/PackageBundle.cs index af97c95..1b12a2a 100644 --- a/Assets/YooAsset/Runtime/PatchSystem/PatchBundle.cs +++ b/Assets/YooAsset/Runtime/PatchSystem/PackageBundle.cs @@ -4,7 +4,7 @@ using System.Linq; namespace YooAsset { [Serializable] - internal class PatchBundle + internal class PackageBundle { /// /// 资源包名称 @@ -173,7 +173,7 @@ namespace YooAsset } - public PatchBundle() + public PackageBundle() { } @@ -183,8 +183,8 @@ namespace YooAsset public void ParseBundle(string packageName, int nameStype) { PackageName = packageName; - _fileExtension = PatchManifestTools.GetRemoteBundleFileExtension(BundleName); - _fileName = PatchManifestTools.GetRemoteBundleFileName(nameStype, BundleName, _fileExtension, FileHash); + _fileExtension = ManifestTools.GetRemoteBundleFileExtension(BundleName); + _fileName = ManifestTools.GetRemoteBundleFileName(nameStype, BundleName, _fileExtension, FileHash); } /// @@ -219,7 +219,7 @@ namespace YooAsset /// /// 检测资源包文件内容是否相同 /// - public bool Equals(PatchBundle otherBundle) + public bool Equals(PackageBundle otherBundle) { if (FileHash == otherBundle.FileHash) return true; diff --git a/Assets/YooAsset/Runtime/PatchSystem/PatchBundle.cs.meta b/Assets/YooAsset/Runtime/PatchSystem/PackageBundle.cs.meta similarity index 100% rename from Assets/YooAsset/Runtime/PatchSystem/PatchBundle.cs.meta rename to Assets/YooAsset/Runtime/PatchSystem/PackageBundle.cs.meta diff --git a/Assets/YooAsset/Runtime/PatchSystem/PatchManifest.cs b/Assets/YooAsset/Runtime/PatchSystem/PackageManifest.cs similarity index 75% rename from Assets/YooAsset/Runtime/PatchSystem/PatchManifest.cs rename to Assets/YooAsset/Runtime/PatchSystem/PackageManifest.cs index 91edb02..78bc911 100644 --- a/Assets/YooAsset/Runtime/PatchSystem/PatchManifest.cs +++ b/Assets/YooAsset/Runtime/PatchSystem/PackageManifest.cs @@ -7,10 +7,10 @@ using System.Collections.Generic; namespace YooAsset { /// - /// 补丁清单文件 + /// 清单文件 /// [Serializable] - internal class PatchManifest + internal class PackageManifest { /// /// 文件版本 @@ -40,25 +40,25 @@ namespace YooAsset /// /// 资源列表(主动收集的资源列表) /// - public List AssetList = new List(); + public List AssetList = new List(); /// /// 资源包列表 /// - public List BundleList = new List(); + public List BundleList = new List(); /// - /// 资源包集合(提供BundleName获取PatchBundle) + /// 资源包集合(提供BundleName获取PackageBundle) /// [NonSerialized] - public Dictionary BundleDic; + public Dictionary BundleDic; /// - /// 资源映射集合(提供AssetPath获取PatchAsset) + /// 资源映射集合(提供AssetPath获取PackageAsset) /// [NonSerialized] - public Dictionary AssetDic; + public Dictionary AssetDic; /// /// 资源路径映射集合 @@ -86,22 +86,22 @@ namespace YooAsset YooLogger.Error("Addressable not support location to lower !"); AssetPathMapping = new Dictionary(AssetList.Count); - foreach (var patchAsset in AssetList) + foreach (var packageAsset in AssetList) { - string location = patchAsset.Address; + string location = packageAsset.Address; if (AssetPathMapping.ContainsKey(location)) throw new Exception($"Address have existed : {location}"); else - AssetPathMapping.Add(location, patchAsset.AssetPath); + AssetPathMapping.Add(location, packageAsset.AssetPath); } } else { _locationToLower = locationToLower; AssetPathMapping = new Dictionary(AssetList.Count * 2); - foreach (var patchAsset in AssetList) + foreach (var packageAsset in AssetList) { - string location = patchAsset.AssetPath; + string location = packageAsset.AssetPath; if (locationToLower) location = location.ToLower(); @@ -109,7 +109,7 @@ namespace YooAsset if (AssetPathMapping.ContainsKey(location)) throw new Exception($"AssetPath have existed : {location}"); else - AssetPathMapping.Add(location, patchAsset.AssetPath); + AssetPathMapping.Add(location, packageAsset.AssetPath); // 添加无后缀名路径的映射 if (Path.HasExtension(location)) @@ -118,7 +118,7 @@ namespace YooAsset if (AssetPathMapping.ContainsKey(locationWithoutExtension)) YooLogger.Warning($"AssetPath have existed : {locationWithoutExtension}"); else - AssetPathMapping.Add(locationWithoutExtension, patchAsset.AssetPath); + AssetPathMapping.Add(locationWithoutExtension, packageAsset.AssetPath); } } } @@ -170,15 +170,15 @@ namespace YooAsset /// 获取主资源包 /// 注意:传入的资源路径一定合法有效! /// - public PatchBundle GetMainPatchBundle(string assetPath) + public PackageBundle GetMainPackageBundle(string assetPath) { - if (AssetDic.TryGetValue(assetPath, out PatchAsset patchAsset)) + if (AssetDic.TryGetValue(assetPath, out PackageAsset packageAsset)) { - int bundleID = patchAsset.BundleID; + int bundleID = packageAsset.BundleID; if (bundleID >= 0 && bundleID < BundleList.Count) { - var patchBundle = BundleList[bundleID]; - return patchBundle; + var packageBundle = BundleList[bundleID]; + return packageBundle; } else { @@ -195,17 +195,17 @@ namespace YooAsset /// 获取资源依赖列表 /// 注意:传入的资源路径一定合法有效! /// - public PatchBundle[] GetAllDependencies(string assetPath) + public PackageBundle[] GetAllDependencies(string assetPath) { - if (AssetDic.TryGetValue(assetPath, out PatchAsset patchAsset)) + if (AssetDic.TryGetValue(assetPath, out PackageAsset packageAsset)) { - List result = new List(patchAsset.DependIDs.Length); - foreach (var dependID in patchAsset.DependIDs) + List result = new List(packageAsset.DependIDs.Length); + foreach (var dependID in packageAsset.DependIDs) { if (dependID >= 0 && dependID < BundleList.Count) { - var dependPatchBundle = BundleList[dependID]; - result.Add(dependPatchBundle); + var dependBundle = BundleList[dependID]; + result.Add(dependBundle); } else { @@ -227,8 +227,8 @@ namespace YooAsset { if (bundleID >= 0 && bundleID < BundleList.Count) { - var patchBundle = BundleList[bundleID]; - return patchBundle.BundleName; + var packageBundle = BundleList[bundleID]; + return packageBundle.BundleName; } else { @@ -237,17 +237,17 @@ namespace YooAsset } /// - /// 尝试获取补丁资源 + /// 尝试获取包裹的资源 /// - public bool TryGetPatchAsset(string assetPath, out PatchAsset result) + public bool TryGetPackageAsset(string assetPath, out PackageAsset result) { return AssetDic.TryGetValue(assetPath, out result); } /// - /// 尝试获取补丁资源包 + /// 尝试获取包裹的资源包 /// - public bool TryGetPatchBundle(string bundleName, out PatchBundle result) + public bool TryGetPackageBundle(string bundleName, out PackageBundle result) { return BundleDic.TryGetValue(bundleName, out result); } @@ -257,9 +257,9 @@ namespace YooAsset /// public bool IsIncludeBundleFile(string cacheGUID) { - foreach (var patchBundle in BundleList) + foreach (var packageBundle in BundleList) { - if (patchBundle.CacheGUID == cacheGUID) + if (packageBundle.CacheGUID == cacheGUID) return true; } return false; @@ -271,11 +271,11 @@ namespace YooAsset public AssetInfo[] GetAssetsInfoByTags(string[] tags) { List result = new List(100); - foreach (var patchAsset in AssetList) + foreach (var packageAsset in AssetList) { - if (patchAsset.HasTag(tags)) + if (packageAsset.HasTag(tags)) { - AssetInfo assetInfo = new AssetInfo(patchAsset); + AssetInfo assetInfo = new AssetInfo(packageAsset); result.Add(assetInfo); } } @@ -291,9 +291,9 @@ namespace YooAsset DebugCheckLocation(location); string assetPath = MappingToAssetPath(location); - if (TryGetPatchAsset(assetPath, out PatchAsset patchAsset)) + if (TryGetPackageAsset(assetPath, out PackageAsset packageAsset)) { - AssetInfo assetInfo = new AssetInfo(patchAsset, assetType); + AssetInfo assetInfo = new AssetInfo(packageAsset, assetType); return assetInfo; } else diff --git a/Assets/YooAsset/Runtime/PatchSystem/PatchManifest.cs.meta b/Assets/YooAsset/Runtime/PatchSystem/PackageManifest.cs.meta similarity index 100% rename from Assets/YooAsset/Runtime/PatchSystem/PatchManifest.cs.meta rename to Assets/YooAsset/Runtime/PatchSystem/PackageManifest.cs.meta diff --git a/Assets/YooAsset/Runtime/PatchSystem/PatchManifestTools.cs b/Assets/YooAsset/Runtime/PatchSystem/PatchManifestTools.cs deleted file mode 100644 index 7378aaf..0000000 --- a/Assets/YooAsset/Runtime/PatchSystem/PatchManifestTools.cs +++ /dev/null @@ -1,193 +0,0 @@ -using System; -using System.IO; -using System.Collections; -using System.Collections.Generic; -using UnityEngine; - -namespace YooAsset -{ - internal static class PatchManifestTools - { - -#if UNITY_EDITOR - /// - /// 序列化(JSON文件) - /// - public static void SerializeToJson(string savePath, PatchManifest manifest) - { - string json = JsonUtility.ToJson(manifest, true); - FileUtility.CreateFile(savePath, json); - } - - /// - /// 序列化(二进制文件) - /// - public static void SerializeToBinary(string savePath, PatchManifest patchManifest) - { - using (FileStream fs = new FileStream(savePath, FileMode.Create)) - { - // 创建缓存器 - BufferWriter buffer = new BufferWriter(YooAssetSettings.PatchManifestFileMaxSize); - - // 写入文件标记 - buffer.WriteUInt32(YooAssetSettings.PatchManifestFileSign); - - // 写入文件版本 - buffer.WriteUTF8(patchManifest.FileVersion); - - // 写入文件头信息 - buffer.WriteBool(patchManifest.EnableAddressable); - buffer.WriteInt32(patchManifest.OutputNameStyle); - buffer.WriteUTF8(patchManifest.PackageName); - buffer.WriteUTF8(patchManifest.PackageVersion); - - // 写入资源列表 - buffer.WriteInt32(patchManifest.AssetList.Count); - for (int i = 0; i < patchManifest.AssetList.Count; i++) - { - var patchAsset = patchManifest.AssetList[i]; - buffer.WriteUTF8(patchAsset.Address); - buffer.WriteUTF8(patchAsset.AssetPath); - buffer.WriteUTF8Array(patchAsset.AssetTags); - buffer.WriteInt32(patchAsset.BundleID); - buffer.WriteInt32Array(patchAsset.DependIDs); - } - - // 写入资源包列表 - buffer.WriteInt32(patchManifest.BundleList.Count); - for (int i = 0; i < patchManifest.BundleList.Count; i++) - { - var patchBundle = patchManifest.BundleList[i]; - buffer.WriteUTF8(patchBundle.BundleName); - buffer.WriteUTF8(patchBundle.FileHash); - buffer.WriteUTF8(patchBundle.FileCRC); - buffer.WriteInt64(patchBundle.FileSize); - buffer.WriteBool(patchBundle.IsRawFile); - buffer.WriteByte(patchBundle.LoadMethod); - buffer.WriteUTF8Array(patchBundle.Tags); - buffer.WriteInt32Array(patchBundle.ReferenceIDs); - } - - // 写入文件流 - buffer.WriteToStream(fs); - fs.Flush(); - } - } - - /// - /// 反序列化(二进制文件) - /// - public static PatchManifest DeserializeFromBinary(byte[] binaryData) - { - // 创建缓存器 - BufferReader buffer = new BufferReader(binaryData); - - // 读取文件标记 - uint fileSign = buffer.ReadUInt32(); - if (fileSign != YooAssetSettings.PatchManifestFileSign) - throw new Exception("Invalid manifest file !"); - - // 读取文件版本 - string fileVersion = buffer.ReadUTF8(); - if (fileVersion != YooAssetSettings.PatchManifestFileVersion) - throw new Exception($"The manifest file version are not compatible : {fileVersion} != {YooAssetSettings.PatchManifestFileVersion}"); - - PatchManifest manifest = new PatchManifest(); - { - // 读取文件头信息 - manifest.FileVersion = fileVersion; - manifest.EnableAddressable = buffer.ReadBool(); - manifest.OutputNameStyle = buffer.ReadInt32(); - manifest.PackageName = buffer.ReadUTF8(); - manifest.PackageVersion = buffer.ReadUTF8(); - - // 读取资源列表 - int patchAssetCount = buffer.ReadInt32(); - manifest.AssetList = new List(patchAssetCount); - for (int i = 0; i < patchAssetCount; i++) - { - var patchAsset = new PatchAsset(); - patchAsset.Address = buffer.ReadUTF8(); - patchAsset.AssetPath = buffer.ReadUTF8(); - patchAsset.AssetTags = buffer.ReadUTF8Array(); - patchAsset.BundleID = buffer.ReadInt32(); - patchAsset.DependIDs = buffer.ReadInt32Array(); - manifest.AssetList.Add(patchAsset); - } - - // 读取资源包列表 - int patchBundleCount = buffer.ReadInt32(); - manifest.BundleList = new List(patchBundleCount); - for (int i = 0; i < patchBundleCount; i++) - { - var patchBundle = new PatchBundle(); - patchBundle.BundleName = buffer.ReadUTF8(); - patchBundle.FileHash = buffer.ReadUTF8(); - patchBundle.FileCRC = buffer.ReadUTF8(); - patchBundle.FileSize = buffer.ReadInt64(); - patchBundle.IsRawFile = buffer.ReadBool(); - patchBundle.LoadMethod = buffer.ReadByte(); - patchBundle.Tags = buffer.ReadUTF8Array(); - patchBundle.ReferenceIDs = buffer.ReadInt32Array(); - manifest.BundleList.Add(patchBundle); - } - } - - // BundleDic - manifest.BundleDic = new Dictionary(manifest.BundleList.Count); - foreach (var patchBundle in manifest.BundleList) - { - patchBundle.ParseBundle(manifest.PackageName, manifest.OutputNameStyle); - manifest.BundleDic.Add(patchBundle.BundleName, patchBundle); - } - - // AssetDic - manifest.AssetDic = new Dictionary(manifest.AssetList.Count); - foreach (var patchAsset in manifest.AssetList) - { - // 注意:我们不允许原始路径存在重名 - string assetPath = patchAsset.AssetPath; - if (manifest.AssetDic.ContainsKey(assetPath)) - throw new Exception($"AssetPath have existed : {assetPath}"); - else - manifest.AssetDic.Add(assetPath, patchAsset); - } - - return manifest; - } -#endif - - public static string GetRemoteBundleFileExtension(string bundleName) - { - string fileExtension = Path.GetExtension(bundleName); - return fileExtension; - } - public static string GetRemoteBundleFileName(int nameStyle, string bundleName, string fileExtension, string fileHash) - { - if (nameStyle == 1) //HashName - { - return StringUtility.Format("{0}{1}", fileHash, fileExtension); - } - else if (nameStyle == 4) //BundleName_HashName - { - string fileName = bundleName.Remove(bundleName.LastIndexOf('.')); - return StringUtility.Format("{0}_{1}{2}", fileName, fileHash, fileExtension); - } - else - { - throw new NotImplementedException($"Invalid name style : {nameStyle}"); - } - } - - /// - /// 获取解压BundleInfo - /// - public static BundleInfo GetUnpackInfo(PatchBundle patchBundle) - { - // 注意:我们把流加载路径指定为远端下载地址 - string streamingPath = PathHelper.ConvertToWWWPath(patchBundle.StreamingFilePath); - BundleInfo bundleInfo = new BundleInfo(patchBundle, BundleInfo.ELoadMode.LoadFromStreaming, streamingPath, streamingPath); - return bundleInfo; - } - } -} \ No newline at end of file diff --git a/Assets/YooAsset/Runtime/PatchSystem/PlayMode/EditorSimulateModeHelper.cs b/Assets/YooAsset/Runtime/PatchSystem/PlayMode/EditorSimulateModeHelper.cs index da0daf9..ef52dd1 100644 --- a/Assets/YooAsset/Runtime/PatchSystem/PlayMode/EditorSimulateModeHelper.cs +++ b/Assets/YooAsset/Runtime/PatchSystem/PlayMode/EditorSimulateModeHelper.cs @@ -8,7 +8,7 @@ namespace YooAsset private static System.Type _classType; /// - /// 编辑器下模拟构建补丁清单 + /// 编辑器下模拟构建清单 /// public static string SimulateBuild(string packageName) { @@ -37,7 +37,7 @@ namespace YooAsset public static class EditorSimulateModeHelper { /// - /// 编辑器下模拟构建补丁清单 + /// 编辑器下模拟构建清单 /// public static string SimulateBuild(string packageName) { throw new System.Exception("Only support in unity editor !"); } } diff --git a/Assets/YooAsset/Runtime/PatchSystem/PlayMode/EditorSimulateModeImpl.cs b/Assets/YooAsset/Runtime/PatchSystem/PlayMode/EditorSimulateModeImpl.cs index ce57146..7ad2489 100644 --- a/Assets/YooAsset/Runtime/PatchSystem/PlayMode/EditorSimulateModeImpl.cs +++ b/Assets/YooAsset/Runtime/PatchSystem/PlayMode/EditorSimulateModeImpl.cs @@ -6,22 +6,22 @@ namespace YooAsset { internal class EditorSimulateModeImpl : IPlayModeServices, IBundleServices { - private PatchManifest _activeManifest; + private PackageManifest _activeManifest; private bool _locationToLower; /// /// 异步初始化 /// - public InitializationOperation InitializeAsync(bool locationToLower, string simulatePatchManifestPath) + public InitializationOperation InitializeAsync(bool locationToLower, string simulateManifestFilePath) { _locationToLower = locationToLower; - var operation = new EditorSimulateModeInitializationOperation(this, simulatePatchManifestPath); + var operation = new EditorSimulateModeInitializationOperation(this, simulateManifestFilePath); OperationSystem.StartOperation(operation); return operation; } #region IPlayModeServices接口 - public PatchManifest ActiveManifest + public PackageManifest ActiveManifest { set { @@ -33,7 +33,7 @@ namespace YooAsset return _activeManifest; } } - public bool IsBuildinPatchBundle(PatchBundle patchBundle) + public bool IsBuildinPackageBundle(PackageBundle packageBundle) { return true; } @@ -50,33 +50,33 @@ namespace YooAsset OperationSystem.StartOperation(operation); return operation; } - PreDownloadPackageOperation IPlayModeServices.PreDownloadPackageAsync(string packageVersion, int timeout) + PreDownloadContentOperation IPlayModeServices.PreDownloadContentAsync(string packageVersion, int timeout) { - var operation = new EditorPlayModePreDownloadPackageOperation(); + var operation = new EditorPlayModePreDownloadContentOperation(); OperationSystem.StartOperation(operation); return operation; } - PatchDownloaderOperation IPlayModeServices.CreatePatchDownloaderByAll(int downloadingMaxNumber, int failedTryAgain, int timeout) + ResourceDownloaderOperation IPlayModeServices.CreateResourceDownloaderByAll(int downloadingMaxNumber, int failedTryAgain, int timeout) { - return PatchDownloaderOperation.CreateEmptyDownloader(downloadingMaxNumber, failedTryAgain, timeout); + return ResourceDownloaderOperation.CreateEmptyDownloader(downloadingMaxNumber, failedTryAgain, timeout); } - PatchDownloaderOperation IPlayModeServices.CreatePatchDownloaderByTags(string[] tags, int downloadingMaxNumber, int failedTryAgain, int timeout) + ResourceDownloaderOperation IPlayModeServices.CreateResourceDownloaderByTags(string[] tags, int downloadingMaxNumber, int failedTryAgain, int timeout) { - return PatchDownloaderOperation.CreateEmptyDownloader(downloadingMaxNumber, failedTryAgain, timeout); + return ResourceDownloaderOperation.CreateEmptyDownloader(downloadingMaxNumber, failedTryAgain, timeout); } - PatchDownloaderOperation IPlayModeServices.CreatePatchDownloaderByPaths(AssetInfo[] assetInfos, int downloadingMaxNumber, int failedTryAgain, int timeout) + ResourceDownloaderOperation IPlayModeServices.CreateResourceDownloaderByPaths(AssetInfo[] assetInfos, int downloadingMaxNumber, int failedTryAgain, int timeout) { - return PatchDownloaderOperation.CreateEmptyDownloader(downloadingMaxNumber, failedTryAgain, timeout); + return ResourceDownloaderOperation.CreateEmptyDownloader(downloadingMaxNumber, failedTryAgain, timeout); } - PatchUnpackerOperation IPlayModeServices.CreatePatchUnpackerByAll(int upackingMaxNumber, int failedTryAgain, int timeout) + ResourceUnpackerOperation IPlayModeServices.CreateResourceUnpackerByAll(int upackingMaxNumber, int failedTryAgain, int timeout) { - return PatchUnpackerOperation.CreateEmptyUnpacker(upackingMaxNumber, failedTryAgain, timeout); + return ResourceUnpackerOperation.CreateEmptyUnpacker(upackingMaxNumber, failedTryAgain, timeout); } - PatchUnpackerOperation IPlayModeServices.CreatePatchUnpackerByTags(string[] tags, int upackingMaxNumber, int failedTryAgain, int timeout) + ResourceUnpackerOperation IPlayModeServices.CreateResourceUnpackerByTags(string[] tags, int upackingMaxNumber, int failedTryAgain, int timeout) { - return PatchUnpackerOperation.CreateEmptyUnpacker(upackingMaxNumber, failedTryAgain, timeout); + return ResourceUnpackerOperation.CreateEmptyUnpacker(upackingMaxNumber, failedTryAgain, timeout); } #endregion @@ -86,9 +86,9 @@ namespace YooAsset if (assetInfo.IsInvalid) throw new Exception("Should never get here !"); - // 注意:如果补丁清单里未找到资源包会抛出异常! - var patchBundle = _activeManifest.GetMainPatchBundle(assetInfo.AssetPath); - BundleInfo bundleInfo = new BundleInfo(patchBundle, BundleInfo.ELoadMode.LoadFromEditor, assetInfo.AssetPath); + // 注意:如果清单里未找到资源包会抛出异常! + var packageBundle = _activeManifest.GetMainPackageBundle(assetInfo.AssetPath); + BundleInfo bundleInfo = new BundleInfo(packageBundle, BundleInfo.ELoadMode.LoadFromEditor, assetInfo.AssetPath); return bundleInfo; } BundleInfo[] IBundleServices.GetAllDependBundleInfos(AssetInfo assetInfo) diff --git a/Assets/YooAsset/Runtime/PatchSystem/PlayMode/HostPlayModeImpl.cs b/Assets/YooAsset/Runtime/PatchSystem/PlayMode/HostPlayModeImpl.cs index 1339fde..025edf1 100644 --- a/Assets/YooAsset/Runtime/PatchSystem/PlayMode/HostPlayModeImpl.cs +++ b/Assets/YooAsset/Runtime/PatchSystem/PlayMode/HostPlayModeImpl.cs @@ -6,7 +6,7 @@ namespace YooAsset { internal class HostPlayModeImpl : IPlayModeServices, IBundleServices, IRemoteServices { - private PatchManifest _activeManifest; + private PackageManifest _activeManifest; // 参数相关 private string _packageName; @@ -32,38 +32,38 @@ namespace YooAsset } // 下载相关 - private List ConvertToDownloadList(List downloadList) + private List ConvertToDownloadList(List downloadList) { List result = new List(downloadList.Count); - foreach (var patchBundle in downloadList) + foreach (var packageBundle in downloadList) { - var bundleInfo = ConvertToDownloadInfo(patchBundle); + var bundleInfo = ConvertToDownloadInfo(packageBundle); result.Add(bundleInfo); } return result; } - private BundleInfo ConvertToDownloadInfo(PatchBundle patchBundle) + private BundleInfo ConvertToDownloadInfo(PackageBundle packageBundle) { - string remoteMainURL = GetRemoteMainURL(patchBundle.FileName); - string remoteFallbackURL = GetRemoteFallbackURL(patchBundle.FileName); - BundleInfo bundleInfo = new BundleInfo(patchBundle, BundleInfo.ELoadMode.LoadFromRemote, remoteMainURL, remoteFallbackURL); + string remoteMainURL = GetRemoteMainURL(packageBundle.FileName); + string remoteFallbackURL = GetRemoteFallbackURL(packageBundle.FileName); + BundleInfo bundleInfo = new BundleInfo(packageBundle, BundleInfo.ELoadMode.LoadFromRemote, remoteMainURL, remoteFallbackURL); return bundleInfo; } // 解压相关 - private List ConvertToUnpackList(List unpackList) + private List ConvertToUnpackList(List unpackList) { List result = new List(unpackList.Count); - foreach (var patchBundle in unpackList) + foreach (var packageBundle in unpackList) { - var bundleInfo = ConvertToUnpackInfo(patchBundle); + var bundleInfo = ConvertToUnpackInfo(packageBundle); result.Add(bundleInfo); } return result; } - private BundleInfo ConvertToUnpackInfo(PatchBundle patchBundle) + private BundleInfo ConvertToUnpackInfo(PackageBundle packageBundle) { - return PatchManifestTools.GetUnpackInfo(patchBundle); + return ManifestTools.GetUnpackInfo(packageBundle); } #region IRemoteServices接口 @@ -78,7 +78,7 @@ namespace YooAsset #endregion #region IPlayModeServices接口 - public PatchManifest ActiveManifest + public PackageManifest ActiveManifest { set { @@ -91,13 +91,13 @@ namespace YooAsset return _activeManifest; } } - public bool IsBuildinPatchBundle(PatchBundle patchBundle) + public bool IsBuildinPackageBundle(PackageBundle packageBundle) { - return _queryServices.QueryStreamingAssets(patchBundle.FileName); + return _queryServices.QueryStreamingAssets(packageBundle.FileName); } - public bool IsCachedPatchBundle(PatchBundle patchBundle) + public bool IsCachedPackageBundle(PackageBundle packageBundle) { - return CacheSystem.IsCached(patchBundle.PackageName, patchBundle.CacheGUID); + return CacheSystem.IsCached(packageBundle.PackageName, packageBundle.CacheGUID); } UpdatePackageVersionOperation IPlayModeServices.UpdatePackageVersionAsync(bool appendTimeTicks, int timeout) @@ -112,68 +112,68 @@ namespace YooAsset OperationSystem.StartOperation(operation); return operation; } - PreDownloadPackageOperation IPlayModeServices.PreDownloadPackageAsync(string packageVersion, int timeout) + PreDownloadContentOperation IPlayModeServices.PreDownloadContentAsync(string packageVersion, int timeout) { - var operation = new HostPlayModePreDownloadPackageOperation(this, _packageName, packageVersion, timeout); + var operation = new HostPlayModePreDownloadContentOperation(this, _packageName, packageVersion, timeout); OperationSystem.StartOperation(operation); return operation; } - PatchDownloaderOperation IPlayModeServices.CreatePatchDownloaderByAll(int downloadingMaxNumber, int failedTryAgain, int timeout) + ResourceDownloaderOperation IPlayModeServices.CreateResourceDownloaderByAll(int downloadingMaxNumber, int failedTryAgain, int timeout) { List downloadList = GetDownloadListByAll(_activeManifest); - var operation = new PatchDownloaderOperation(downloadList, downloadingMaxNumber, failedTryAgain, timeout); + var operation = new ResourceDownloaderOperation(downloadList, downloadingMaxNumber, failedTryAgain, timeout); return operation; } - public List GetDownloadListByAll(PatchManifest patchManifest) + public List GetDownloadListByAll(PackageManifest manifest) { - List downloadList = new List(1000); - foreach (var patchBundle in patchManifest.BundleList) + List downloadList = new List(1000); + foreach (var packageBundle in manifest.BundleList) { // 忽略缓存文件 - if (IsCachedPatchBundle(patchBundle)) + if (IsCachedPackageBundle(packageBundle)) continue; // 忽略APP资源 - if (IsBuildinPatchBundle(patchBundle)) + if (IsBuildinPackageBundle(packageBundle)) continue; - downloadList.Add(patchBundle); + downloadList.Add(packageBundle); } return ConvertToDownloadList(downloadList); } - PatchDownloaderOperation IPlayModeServices.CreatePatchDownloaderByTags(string[] tags, int downloadingMaxNumber, int failedTryAgain, int timeout) + ResourceDownloaderOperation IPlayModeServices.CreateResourceDownloaderByTags(string[] tags, int downloadingMaxNumber, int failedTryAgain, int timeout) { List downloadList = GetDownloadListByTags(_activeManifest, tags); - var operation = new PatchDownloaderOperation(downloadList, downloadingMaxNumber, failedTryAgain, timeout); + var operation = new ResourceDownloaderOperation(downloadList, downloadingMaxNumber, failedTryAgain, timeout); return operation; } - public List GetDownloadListByTags(PatchManifest patchManifest, string[] tags) + public List GetDownloadListByTags(PackageManifest manifest, string[] tags) { - List downloadList = new List(1000); - foreach (var patchBundle in patchManifest.BundleList) + List downloadList = new List(1000); + foreach (var packageBundle in manifest.BundleList) { // 忽略缓存文件 - if (IsCachedPatchBundle(patchBundle)) + if (IsCachedPackageBundle(packageBundle)) continue; // 忽略APP资源 - if (IsBuildinPatchBundle(patchBundle)) + if (IsBuildinPackageBundle(packageBundle)) continue; // 如果未带任何标记,则统一下载 - if (patchBundle.HasAnyTags() == false) + if (packageBundle.HasAnyTags() == false) { - downloadList.Add(patchBundle); + downloadList.Add(packageBundle); } else { // 查询DLC资源 - if (patchBundle.HasTag(tags)) + if (packageBundle.HasTag(tags)) { - downloadList.Add(patchBundle); + downloadList.Add(packageBundle); } } } @@ -181,16 +181,16 @@ namespace YooAsset return ConvertToDownloadList(downloadList); } - PatchDownloaderOperation IPlayModeServices.CreatePatchDownloaderByPaths(AssetInfo[] assetInfos, int downloadingMaxNumber, int failedTryAgain, int timeout) + ResourceDownloaderOperation IPlayModeServices.CreateResourceDownloaderByPaths(AssetInfo[] assetInfos, int downloadingMaxNumber, int failedTryAgain, int timeout) { List downloadList = GetDownloadListByPaths(_activeManifest, assetInfos); - var operation = new PatchDownloaderOperation(downloadList, downloadingMaxNumber, failedTryAgain, timeout); + var operation = new ResourceDownloaderOperation(downloadList, downloadingMaxNumber, failedTryAgain, timeout); return operation; } - public List GetDownloadListByPaths(PatchManifest patchManifest, AssetInfo[] assetInfos) + public List GetDownloadListByPaths(PackageManifest manifest, AssetInfo[] assetInfos) { // 获取资源对象的资源包和所有依赖资源包 - List checkList = new List(); + List checkList = new List(); foreach (var assetInfo in assetInfos) { if (assetInfo.IsInvalid) @@ -199,13 +199,13 @@ namespace YooAsset continue; } - // 注意:如果补丁清单里未找到资源包会抛出异常! - PatchBundle mainBundle = patchManifest.GetMainPatchBundle(assetInfo.AssetPath); + // 注意:如果清单里未找到资源包会抛出异常! + PackageBundle mainBundle = manifest.GetMainPackageBundle(assetInfo.AssetPath); if (checkList.Contains(mainBundle) == false) checkList.Add(mainBundle); - // 注意:如果补丁清单里未找到资源包会抛出异常! - PatchBundle[] dependBundles = patchManifest.GetAllDependencies(assetInfo.AssetPath); + // 注意:如果清单里未找到资源包会抛出异常! + PackageBundle[] dependBundles = manifest.GetAllDependencies(assetInfo.AssetPath); foreach (var dependBundle in dependBundles) { if (checkList.Contains(dependBundle) == false) @@ -213,68 +213,68 @@ namespace YooAsset } } - List downloadList = new List(1000); - foreach (var patchBundle in checkList) + List downloadList = new List(1000); + foreach (var packageBundle in checkList) { // 忽略缓存文件 - if (IsCachedPatchBundle(patchBundle)) + if (IsCachedPackageBundle(packageBundle)) continue; // 忽略APP资源 - if (IsBuildinPatchBundle(patchBundle)) + if (IsBuildinPackageBundle(packageBundle)) continue; - downloadList.Add(patchBundle); + downloadList.Add(packageBundle); } return ConvertToDownloadList(downloadList); } - PatchUnpackerOperation IPlayModeServices.CreatePatchUnpackerByAll(int upackingMaxNumber, int failedTryAgain, int timeout) + ResourceUnpackerOperation IPlayModeServices.CreateResourceUnpackerByAll(int upackingMaxNumber, int failedTryAgain, int timeout) { List unpcakList = GetUnpackListByAll(_activeManifest); - var operation = new PatchUnpackerOperation(unpcakList, upackingMaxNumber, failedTryAgain, timeout); + var operation = new ResourceUnpackerOperation(unpcakList, upackingMaxNumber, failedTryAgain, timeout); return operation; } - private List GetUnpackListByAll(PatchManifest patchManifest) + private List GetUnpackListByAll(PackageManifest manifest) { - List downloadList = new List(1000); - foreach (var patchBundle in patchManifest.BundleList) + List downloadList = new List(1000); + foreach (var packageBundle in manifest.BundleList) { // 忽略缓存文件 - if (IsCachedPatchBundle(patchBundle)) + if (IsCachedPackageBundle(packageBundle)) continue; - if (IsBuildinPatchBundle(patchBundle)) + if (IsBuildinPackageBundle(packageBundle)) { - downloadList.Add(patchBundle); + downloadList.Add(packageBundle); } } return ConvertToUnpackList(downloadList); } - PatchUnpackerOperation IPlayModeServices.CreatePatchUnpackerByTags(string[] tags, int upackingMaxNumber, int failedTryAgain, int timeout) + ResourceUnpackerOperation IPlayModeServices.CreateResourceUnpackerByTags(string[] tags, int upackingMaxNumber, int failedTryAgain, int timeout) { List unpcakList = GetUnpackListByTags(_activeManifest, tags); - var operation = new PatchUnpackerOperation(unpcakList, upackingMaxNumber, failedTryAgain, timeout); + var operation = new ResourceUnpackerOperation(unpcakList, upackingMaxNumber, failedTryAgain, timeout); return operation; } - private List GetUnpackListByTags(PatchManifest patchManifest, string[] tags) + private List GetUnpackListByTags(PackageManifest manifest, string[] tags) { - List downloadList = new List(1000); - foreach (var patchBundle in patchManifest.BundleList) + List downloadList = new List(1000); + foreach (var packageBundle in manifest.BundleList) { // 忽略缓存文件 - if (IsCachedPatchBundle(patchBundle)) + if (IsCachedPackageBundle(packageBundle)) continue; // 查询DLC资源 - if (IsBuildinPatchBundle(patchBundle)) + if (IsBuildinPackageBundle(packageBundle)) { - if (patchBundle.HasTag(tags)) + if (packageBundle.HasTag(tags)) { - downloadList.Add(patchBundle); + downloadList.Add(packageBundle); } } } @@ -284,48 +284,48 @@ namespace YooAsset #endregion #region IBundleServices接口 - private BundleInfo CreateBundleInfo(PatchBundle patchBundle) + private BundleInfo CreateBundleInfo(PackageBundle packageBundle) { - if (patchBundle == null) + if (packageBundle == null) throw new Exception("Should never get here !"); // 查询沙盒资源 - if (IsCachedPatchBundle(patchBundle)) + if (IsCachedPackageBundle(packageBundle)) { - BundleInfo bundleInfo = new BundleInfo(patchBundle, BundleInfo.ELoadMode.LoadFromCache); + BundleInfo bundleInfo = new BundleInfo(packageBundle, BundleInfo.ELoadMode.LoadFromCache); return bundleInfo; } // 查询APP资源 - if (IsBuildinPatchBundle(patchBundle)) + if (IsBuildinPackageBundle(packageBundle)) { - BundleInfo bundleInfo = new BundleInfo(patchBundle, BundleInfo.ELoadMode.LoadFromStreaming); + BundleInfo bundleInfo = new BundleInfo(packageBundle, BundleInfo.ELoadMode.LoadFromStreaming); return bundleInfo; } // 从服务端下载 - return ConvertToDownloadInfo(patchBundle); + return ConvertToDownloadInfo(packageBundle); } BundleInfo IBundleServices.GetBundleInfo(AssetInfo assetInfo) { if (assetInfo.IsInvalid) throw new Exception("Should never get here !"); - // 注意:如果补丁清单里未找到资源包会抛出异常! - var patchBundle = _activeManifest.GetMainPatchBundle(assetInfo.AssetPath); - return CreateBundleInfo(patchBundle); + // 注意:如果清单里未找到资源包会抛出异常! + var packageBundle = _activeManifest.GetMainPackageBundle(assetInfo.AssetPath); + return CreateBundleInfo(packageBundle); } BundleInfo[] IBundleServices.GetAllDependBundleInfos(AssetInfo assetInfo) { if (assetInfo.IsInvalid) throw new Exception("Should never get here !"); - // 注意:如果补丁清单里未找到资源包会抛出异常! + // 注意:如果清单里未找到资源包会抛出异常! var depends = _activeManifest.GetAllDependencies(assetInfo.AssetPath); List result = new List(depends.Length); - foreach (var patchBundle in depends) + foreach (var packageBundle in depends) { - BundleInfo bundleInfo = CreateBundleInfo(patchBundle); + BundleInfo bundleInfo = CreateBundleInfo(packageBundle); result.Add(bundleInfo); } return result.ToArray(); diff --git a/Assets/YooAsset/Runtime/PatchSystem/PlayMode/OfflinePlayModeImpl.cs b/Assets/YooAsset/Runtime/PatchSystem/PlayMode/OfflinePlayModeImpl.cs index 5ce8832..37617aa 100644 --- a/Assets/YooAsset/Runtime/PatchSystem/PlayMode/OfflinePlayModeImpl.cs +++ b/Assets/YooAsset/Runtime/PatchSystem/PlayMode/OfflinePlayModeImpl.cs @@ -6,7 +6,7 @@ namespace YooAsset { internal class OfflinePlayModeImpl : IPlayModeServices, IBundleServices { - private PatchManifest _activeManifest; + private PackageManifest _activeManifest; private bool _locationToLower; /// @@ -21,7 +21,7 @@ namespace YooAsset } #region IPlayModeServices接口 - public PatchManifest ActiveManifest + public PackageManifest ActiveManifest { set { @@ -33,7 +33,7 @@ namespace YooAsset return _activeManifest; } } - public bool IsBuildinPatchBundle(PatchBundle patchBundle) + public bool IsBuildinPackageBundle(PackageBundle packageBundle) { return true; } @@ -50,52 +50,52 @@ namespace YooAsset OperationSystem.StartOperation(operation); return operation; } - PreDownloadPackageOperation IPlayModeServices.PreDownloadPackageAsync(string packageVersion, int timeout) + PreDownloadContentOperation IPlayModeServices.PreDownloadContentAsync(string packageVersion, int timeout) { - var operation = new OfflinePlayModePreDownloadPackageOperation(); + var operation = new OfflinePlayModePreDownloadContentOperation(); OperationSystem.StartOperation(operation); return operation; } - PatchDownloaderOperation IPlayModeServices.CreatePatchDownloaderByAll(int downloadingMaxNumber, int failedTryAgain, int timeout) + ResourceDownloaderOperation IPlayModeServices.CreateResourceDownloaderByAll(int downloadingMaxNumber, int failedTryAgain, int timeout) { - return PatchDownloaderOperation.CreateEmptyDownloader(downloadingMaxNumber, failedTryAgain, timeout); + return ResourceDownloaderOperation.CreateEmptyDownloader(downloadingMaxNumber, failedTryAgain, timeout); } - PatchDownloaderOperation IPlayModeServices.CreatePatchDownloaderByTags(string[] tags, int downloadingMaxNumber, int failedTryAgain, int timeout) + ResourceDownloaderOperation IPlayModeServices.CreateResourceDownloaderByTags(string[] tags, int downloadingMaxNumber, int failedTryAgain, int timeout) { - return PatchDownloaderOperation.CreateEmptyDownloader(downloadingMaxNumber, failedTryAgain, timeout); + return ResourceDownloaderOperation.CreateEmptyDownloader(downloadingMaxNumber, failedTryAgain, timeout); } - PatchDownloaderOperation IPlayModeServices.CreatePatchDownloaderByPaths(AssetInfo[] assetInfos, int downloadingMaxNumber, int failedTryAgain, int timeout) + ResourceDownloaderOperation IPlayModeServices.CreateResourceDownloaderByPaths(AssetInfo[] assetInfos, int downloadingMaxNumber, int failedTryAgain, int timeout) { - return PatchDownloaderOperation.CreateEmptyDownloader(downloadingMaxNumber, failedTryAgain, timeout); + return ResourceDownloaderOperation.CreateEmptyDownloader(downloadingMaxNumber, failedTryAgain, timeout); } - PatchUnpackerOperation IPlayModeServices.CreatePatchUnpackerByAll(int upackingMaxNumber, int failedTryAgain, int timeout) + ResourceUnpackerOperation IPlayModeServices.CreateResourceUnpackerByAll(int upackingMaxNumber, int failedTryAgain, int timeout) { - return PatchUnpackerOperation.CreateEmptyUnpacker(upackingMaxNumber, failedTryAgain, timeout); + return ResourceUnpackerOperation.CreateEmptyUnpacker(upackingMaxNumber, failedTryAgain, timeout); } - PatchUnpackerOperation IPlayModeServices.CreatePatchUnpackerByTags(string[] tags, int upackingMaxNumber, int failedTryAgain, int timeout) + ResourceUnpackerOperation IPlayModeServices.CreateResourceUnpackerByTags(string[] tags, int upackingMaxNumber, int failedTryAgain, int timeout) { - return PatchUnpackerOperation.CreateEmptyUnpacker(upackingMaxNumber, failedTryAgain, timeout); + return ResourceUnpackerOperation.CreateEmptyUnpacker(upackingMaxNumber, failedTryAgain, timeout); } #endregion #region IBundleServices接口 - private BundleInfo CreateBundleInfo(PatchBundle patchBundle) + private BundleInfo CreateBundleInfo(PackageBundle packageBundle) { - if (patchBundle == null) + if (packageBundle == null) throw new Exception("Should never get here !"); // 查询沙盒资源 - if (CacheSystem.IsCached(patchBundle.PackageName, patchBundle.CacheGUID)) + if (CacheSystem.IsCached(packageBundle.PackageName, packageBundle.CacheGUID)) { - BundleInfo bundleInfo = new BundleInfo(patchBundle, BundleInfo.ELoadMode.LoadFromCache); + BundleInfo bundleInfo = new BundleInfo(packageBundle, BundleInfo.ELoadMode.LoadFromCache); return bundleInfo; } // 查询APP资源 { - BundleInfo bundleInfo = new BundleInfo(patchBundle, BundleInfo.ELoadMode.LoadFromStreaming); + BundleInfo bundleInfo = new BundleInfo(packageBundle, BundleInfo.ELoadMode.LoadFromStreaming); return bundleInfo; } } @@ -104,21 +104,21 @@ namespace YooAsset if (assetInfo.IsInvalid) throw new Exception("Should never get here !"); - // 注意:如果补丁清单里未找到资源包会抛出异常! - var patchBundle = _activeManifest.GetMainPatchBundle(assetInfo.AssetPath); - return CreateBundleInfo(patchBundle); + // 注意:如果清单里未找到资源包会抛出异常! + var packageBundle = _activeManifest.GetMainPackageBundle(assetInfo.AssetPath); + return CreateBundleInfo(packageBundle); } BundleInfo[] IBundleServices.GetAllDependBundleInfos(AssetInfo assetInfo) { if (assetInfo.IsInvalid) throw new Exception("Should never get here !"); - // 注意:如果补丁清单里未找到资源包会抛出异常! + // 注意:如果清单里未找到资源包会抛出异常! var depends = _activeManifest.GetAllDependencies(assetInfo.AssetPath); List result = new List(depends.Length); - foreach (var patchBundle in depends) + foreach (var packageBundle in depends) { - BundleInfo bundleInfo = CreateBundleInfo(patchBundle); + BundleInfo bundleInfo = CreateBundleInfo(packageBundle); result.Add(bundleInfo); } return result.ToArray(); diff --git a/Assets/YooAsset/Runtime/AssetsPackage.cs b/Assets/YooAsset/Runtime/ResourcePackage.cs similarity index 81% rename from Assets/YooAsset/Runtime/AssetsPackage.cs rename to Assets/YooAsset/Runtime/ResourcePackage.cs index 06f2361..8091bc3 100644 --- a/Assets/YooAsset/Runtime/AssetsPackage.cs +++ b/Assets/YooAsset/Runtime/ResourcePackage.cs @@ -6,7 +6,7 @@ using UnityEngine.SceneManagement; namespace YooAsset { - public class AssetsPackage + public class ResourcePackage { private bool _isInitialize = false; private string _initializeError = string.Empty; @@ -30,10 +30,10 @@ namespace YooAsset } - private AssetsPackage() + private ResourcePackage() { } - internal AssetsPackage(string packageName) + internal ResourcePackage(string packageName) { PackageName = packageName; } @@ -90,7 +90,7 @@ namespace YooAsset _assetSystemImpl.Initialize(PackageName, true, parameters.AssetLoadingMaxNumber, parameters.DecryptionServices, _bundleServices); var initializeParameters = parameters as EditorSimulateModeParameters; - initializeOperation = editorSimulateModeImpl.InitializeAsync(initializeParameters.LocationToLower, initializeParameters.SimulatePatchManifestPath); + initializeOperation = editorSimulateModeImpl.InitializeAsync(initializeParameters.LocationToLower, initializeParameters.SimulateManifestFilePath); } else if (_playMode == EPlayMode.OfflinePlayMode) { @@ -143,10 +143,10 @@ namespace YooAsset private void CheckInitializeParameters(InitializeParameters parameters) { if (_isInitialize) - throw new Exception($"{nameof(AssetsPackage)} is initialized yet."); + throw new Exception($"{nameof(ResourcePackage)} is initialized yet."); if (parameters == null) - throw new Exception($"{nameof(AssetsPackage)} create parameters is null."); + throw new Exception($"{nameof(ResourcePackage)} create parameters is null."); #if !UNITY_EDITOR if (parameters is EditorSimulateModeParameters) @@ -156,8 +156,8 @@ namespace YooAsset if (parameters is EditorSimulateModeParameters) { var editorSimulateModeParameters = parameters as EditorSimulateModeParameters; - if (string.IsNullOrEmpty(editorSimulateModeParameters.SimulatePatchManifestPath)) - throw new Exception($"{nameof(editorSimulateModeParameters.SimulatePatchManifestPath)} is null or empty."); + if (string.IsNullOrEmpty(editorSimulateModeParameters.SimulateManifestFilePath)) + throw new Exception($"{nameof(editorSimulateModeParameters.SimulateManifestFilePath)} is null or empty."); } if (parameters is HostPlayModeParameters) @@ -206,7 +206,7 @@ namespace YooAsset } /// - /// 向网络端请求并更新补丁清单 + /// 向网络端请求并更新清单 /// /// 更新的包裹版本 /// 自动激活清单 @@ -223,12 +223,12 @@ namespace YooAsset /// /// 下载的包裹版本 /// 超时时间(默认值:60秒) - public PreDownloadPackageOperation PreDownloadPackageAsync(string packageVersion, int timeout = 60) + public PreDownloadContentOperation PreDownloadContentAsync(string packageVersion, int timeout = 60) { DebugCheckInitialize(); - return _playModeServices.PreDownloadPackageAsync(packageVersion, timeout); + return _playModeServices.PreDownloadContentAsync(packageVersion, timeout); } - + /// /// 清理包裹未使用的缓存文件 /// @@ -630,91 +630,139 @@ namespace YooAsset #region 资源下载 /// - /// 创建补丁下载器,用于下载更新资源标签指定的资源包文件 + /// 创建资源下载器,用于下载当前资源版本所有的资源包文件 + /// + /// 同时下载的最大文件数 + /// 下载失败的重试次数 + /// 超时时间 + public ResourceDownloaderOperation CreateResourceDownloader(int downloadingMaxNumber, int failedTryAgain, int timeout = 60) + { + DebugCheckInitialize(); + return _playModeServices.CreateResourceDownloaderByAll(downloadingMaxNumber, failedTryAgain, timeout); + } + + /// + /// 创建资源下载器,用于下载指定的资源标签关联的资源包文件 /// /// 资源标签 /// 同时下载的最大文件数 /// 下载失败的重试次数 /// 超时时间 - public PatchDownloaderOperation CreatePatchDownloader(string tag, int downloadingMaxNumber, int failedTryAgain, int timeout = 60) + public ResourceDownloaderOperation CreateResourceDownloader(string tag, int downloadingMaxNumber, int failedTryAgain, int timeout = 60) { DebugCheckInitialize(); - return _playModeServices.CreatePatchDownloaderByTags(new string[] { tag }, downloadingMaxNumber, failedTryAgain, timeout); + return _playModeServices.CreateResourceDownloaderByTags(new string[] { tag }, downloadingMaxNumber, failedTryAgain, timeout); } /// - /// 创建补丁下载器,用于下载更新资源标签指定的资源包文件 + /// 创建资源下载器,用于下载指定的资源标签列表关联的资源包文件 /// /// 资源标签列表 /// 同时下载的最大文件数 /// 下载失败的重试次数 /// 超时时间 - public PatchDownloaderOperation CreatePatchDownloader(string[] tags, int downloadingMaxNumber, int failedTryAgain, int timeout = 60) + public ResourceDownloaderOperation CreateResourceDownloader(string[] tags, int downloadingMaxNumber, int failedTryAgain, int timeout = 60) { DebugCheckInitialize(); - return _playModeServices.CreatePatchDownloaderByTags(tags, downloadingMaxNumber, failedTryAgain, timeout); + return _playModeServices.CreateResourceDownloaderByTags(tags, downloadingMaxNumber, failedTryAgain, timeout); } /// - /// 创建补丁下载器,用于下载更新当前资源版本所有的资源包文件 + /// 创建资源下载器,用于下载指定的资源依赖的资源包文件 /// + /// 资源的定位地址 /// 同时下载的最大文件数 /// 下载失败的重试次数 /// 超时时间 - public PatchDownloaderOperation CreatePatchDownloader(int downloadingMaxNumber, int failedTryAgain, int timeout = 60) + public ResourceDownloaderOperation CreateBundleDownloader(string location, int downloadingMaxNumber, int failedTryAgain, int timeout = 60) { DebugCheckInitialize(); - return _playModeServices.CreatePatchDownloaderByAll(downloadingMaxNumber, failedTryAgain, timeout); + var assetInfo = ConvertLocationToAssetInfo(location, null); + AssetInfo[] assetInfos = new AssetInfo[] { assetInfo }; + return _playModeServices.CreateResourceDownloaderByPaths(assetInfos, downloadingMaxNumber, failedTryAgain, timeout); } /// - /// 创建补丁下载器,用于下载更新指定的资源列表依赖的资源包文件 + /// 创建资源下载器,用于下载指定的资源列表依赖的资源包文件 + /// + /// 资源的定位地址列表 + /// 同时下载的最大文件数 + /// 下载失败的重试次数 + /// 超时时间 + public ResourceDownloaderOperation CreateBundleDownloader(string[] locations, int downloadingMaxNumber, int failedTryAgain, int timeout = 60) + { + DebugCheckInitialize(); + List assetInfos = new List(locations.Length); + foreach (var location in locations) + { + var assetInfo = ConvertLocationToAssetInfo(location, null); + assetInfos.Add(assetInfo); + } + return _playModeServices.CreateResourceDownloaderByPaths(assetInfos.ToArray(), downloadingMaxNumber, failedTryAgain, timeout); + } + + /// + /// 创建资源下载器,用于下载指定的资源依赖的资源包文件 + /// + /// 资源信息 + /// 同时下载的最大文件数 + /// 下载失败的重试次数 + /// 超时时间 + public ResourceDownloaderOperation CreateBundleDownloader(AssetInfo assetInfo, int downloadingMaxNumber, int failedTryAgain, int timeout = 60) + { + DebugCheckInitialize(); + AssetInfo[] assetInfos = new AssetInfo[] { assetInfo }; + return _playModeServices.CreateResourceDownloaderByPaths(assetInfos, downloadingMaxNumber, failedTryAgain, timeout); + } + + /// + /// 创建资源下载器,用于下载指定的资源列表依赖的资源包文件 /// /// 资源信息列表 /// 同时下载的最大文件数 /// 下载失败的重试次数 /// 超时时间 - public PatchDownloaderOperation CreateBundleDownloader(AssetInfo[] assetInfos, int downloadingMaxNumber, int failedTryAgain, int timeout = 60) + public ResourceDownloaderOperation CreateBundleDownloader(AssetInfo[] assetInfos, int downloadingMaxNumber, int failedTryAgain, int timeout = 60) { DebugCheckInitialize(); - return _playModeServices.CreatePatchDownloaderByPaths(assetInfos, downloadingMaxNumber, failedTryAgain, timeout); + return _playModeServices.CreateResourceDownloaderByPaths(assetInfos, downloadingMaxNumber, failedTryAgain, timeout); } #endregion #region 资源解压 /// - /// 创建补丁解压器 + /// 创建内置资源解压器 /// /// 资源标签 /// 同时解压的最大文件数 /// 解压失败的重试次数 - public PatchUnpackerOperation CreatePatchUnpacker(string tag, int unpackingMaxNumber, int failedTryAgain) + public ResourceUnpackerOperation CreateResourceUnpacker(string tag, int unpackingMaxNumber, int failedTryAgain) { DebugCheckInitialize(); - return _playModeServices.CreatePatchUnpackerByTags(new string[] { tag }, unpackingMaxNumber, failedTryAgain, int.MaxValue); + return _playModeServices.CreateResourceUnpackerByTags(new string[] { tag }, unpackingMaxNumber, failedTryAgain, int.MaxValue); } /// - /// 创建补丁解压器 + /// 创建内置资源解压器 /// /// 资源标签列表 /// 同时解压的最大文件数 /// 解压失败的重试次数 - public PatchUnpackerOperation CreatePatchUnpacker(string[] tags, int unpackingMaxNumber, int failedTryAgain) + public ResourceUnpackerOperation CreateResourceUnpacker(string[] tags, int unpackingMaxNumber, int failedTryAgain) { DebugCheckInitialize(); - return _playModeServices.CreatePatchUnpackerByTags(tags, unpackingMaxNumber, failedTryAgain, int.MaxValue); + return _playModeServices.CreateResourceUnpackerByTags(tags, unpackingMaxNumber, failedTryAgain, int.MaxValue); } /// - /// 创建补丁解压器 + /// 创建内置资源解压器 /// /// 同时解压的最大文件数 /// 解压失败的重试次数 - public PatchUnpackerOperation CreatePatchUnpacker(int unpackingMaxNumber, int failedTryAgain) + public ResourceUnpackerOperation CreateResourceUnpacker(int unpackingMaxNumber, int failedTryAgain) { DebugCheckInitialize(); - return _playModeServices.CreatePatchUnpackerByAll(unpackingMaxNumber, failedTryAgain, int.MaxValue); + return _playModeServices.CreateResourceUnpackerByAll(unpackingMaxNumber, failedTryAgain, int.MaxValue); } #endregion diff --git a/Assets/YooAsset/Runtime/AssetsPackage.cs.meta b/Assets/YooAsset/Runtime/ResourcePackage.cs.meta similarity index 100% rename from Assets/YooAsset/Runtime/AssetsPackage.cs.meta rename to Assets/YooAsset/Runtime/ResourcePackage.cs.meta diff --git a/Assets/YooAsset/Runtime/Services/Internal/IPlayModeServices.cs b/Assets/YooAsset/Runtime/Services/Internal/IPlayModeServices.cs index 161567c..0c8a5fb 100644 --- a/Assets/YooAsset/Runtime/Services/Internal/IPlayModeServices.cs +++ b/Assets/YooAsset/Runtime/Services/Internal/IPlayModeServices.cs @@ -6,12 +6,12 @@ namespace YooAsset /// /// 激活的清单 /// - PatchManifest ActiveManifest { set; get; } + PackageManifest ActiveManifest { set; get; } /// /// 是否为内置资源文件 /// - bool IsBuildinPatchBundle(PatchBundle patchBundle); + bool IsBuildinPackageBundle(PackageBundle packageBundle); /// /// 向网络端请求最新的资源版本 @@ -19,22 +19,22 @@ namespace YooAsset UpdatePackageVersionOperation UpdatePackageVersionAsync(bool appendTimeTicks, int timeout); /// - /// 向网络端请求并更新补丁清单 + /// 向网络端请求并更新清单 /// UpdatePackageManifestOperation UpdatePackageManifestAsync(string packageVersion, int timeout); /// - /// 预下载指定版本的包裹资源 + /// 预下载指定版本的包裹内容 /// - PreDownloadPackageOperation PreDownloadPackageAsync(string packageVersion, int timeout); + PreDownloadContentOperation PreDownloadContentAsync(string packageVersion, int timeout); // 下载相关 - PatchDownloaderOperation CreatePatchDownloaderByAll(int downloadingMaxNumber, int failedTryAgain, int timeout); - PatchDownloaderOperation CreatePatchDownloaderByTags(string[] tags, int downloadingMaxNumber, int failedTryAgain, int timeout); - PatchDownloaderOperation CreatePatchDownloaderByPaths(AssetInfo[] assetInfos, int downloadingMaxNumber, int failedTryAgain, int timeout); + ResourceDownloaderOperation CreateResourceDownloaderByAll(int downloadingMaxNumber, int failedTryAgain, int timeout); + ResourceDownloaderOperation CreateResourceDownloaderByTags(string[] tags, int downloadingMaxNumber, int failedTryAgain, int timeout); + ResourceDownloaderOperation CreateResourceDownloaderByPaths(AssetInfo[] assetInfos, int downloadingMaxNumber, int failedTryAgain, int timeout); // 解压相关 - PatchUnpackerOperation CreatePatchUnpackerByAll(int upackingMaxNumber, int failedTryAgain, int timeout); - PatchUnpackerOperation CreatePatchUnpackerByTags(string[] tags, int upackingMaxNumber, int failedTryAgain, int timeout); + ResourceUnpackerOperation CreateResourceUnpackerByAll(int upackingMaxNumber, int failedTryAgain, int timeout); + ResourceUnpackerOperation CreateResourceUnpackerByTags(string[] tags, int upackingMaxNumber, int failedTryAgain, int timeout); } } \ No newline at end of file diff --git a/Assets/YooAsset/Runtime/Settings/YooAssetSettings.cs b/Assets/YooAsset/Runtime/Settings/YooAssetSettings.cs index 2f91fe4..8696b05 100644 --- a/Assets/YooAsset/Runtime/Settings/YooAssetSettings.cs +++ b/Assets/YooAsset/Runtime/Settings/YooAssetSettings.cs @@ -8,23 +8,23 @@ namespace YooAsset /// /// 清单文件名称 /// - public string PatchManifestFileName = "PatchManifest"; + public string ManifestFileName = "PackageManifest"; /// /// 清单文件头标记 /// - public const uint PatchManifestFileSign = 0x594F4F; + public const uint ManifestFileSign = 0x594F4F; /// /// 清单文件极限大小(100MB) /// - public const int PatchManifestFileMaxSize = 104857600; + public const int ManifestFileMaxSize = 104857600; /// /// 清单文件格式版本 /// - public const string PatchManifestFileVersion = "1.4.6"; + public const string ManifestFileVersion = "1.4.6"; /// diff --git a/Assets/YooAsset/Runtime/Settings/YooAssetSettingsData.cs b/Assets/YooAsset/Runtime/Settings/YooAssetSettingsData.cs index f30b5b9..16ac6b8 100644 --- a/Assets/YooAsset/Runtime/Settings/YooAssetSettingsData.cs +++ b/Assets/YooAsset/Runtime/Settings/YooAssetSettingsData.cs @@ -45,7 +45,7 @@ namespace YooAsset /// public static string GetManifestBinaryFileName(string packageName, string packageVersion) { - return $"{Setting.PatchManifestFileName}_{packageName}_{packageVersion}.bytes"; + return $"{Setting.ManifestFileName}_{packageName}_{packageVersion}.bytes"; } /// @@ -53,7 +53,7 @@ namespace YooAsset /// public static string GetManifestJsonFileName(string packageName, string packageVersion) { - return $"{Setting.PatchManifestFileName}_{packageName}_{packageVersion}.json"; + return $"{Setting.ManifestFileName}_{packageName}_{packageVersion}.json"; } /// @@ -61,7 +61,7 @@ namespace YooAsset /// public static string GetPackageHashFileName(string packageName, string packageVersion) { - return $"{Setting.PatchManifestFileName}_{packageName}_{packageVersion}.hash"; + return $"{Setting.ManifestFileName}_{packageName}_{packageVersion}.hash"; } /// @@ -69,7 +69,7 @@ namespace YooAsset /// public static string GetPackageVersionFileName(string packageName) { - return $"{Setting.PatchManifestFileName}_{packageName}.version"; + return $"{Setting.ManifestFileName}_{packageName}.version"; } } } \ No newline at end of file diff --git a/Assets/YooAsset/Runtime/YooAssets.cs b/Assets/YooAsset/Runtime/YooAssets.cs index 619e7ef..1cd9c73 100644 --- a/Assets/YooAsset/Runtime/YooAssets.cs +++ b/Assets/YooAsset/Runtime/YooAssets.cs @@ -10,7 +10,7 @@ namespace YooAsset { private static bool _isInitialize = false; private static GameObject _driver = null; - private static readonly List _packages = new List(); + private static readonly List _packages = new List(); /// /// 初始化资源系统 @@ -88,7 +88,7 @@ namespace YooAsset /// 创建资源包 /// /// 资源包名称 - public static AssetsPackage CreateAssetsPackage(string packageName) + public static ResourcePackage CreatePackage(string packageName) { if (_isInitialize == false) throw new Exception($"{nameof(YooAssets)} not initialize !"); @@ -96,23 +96,23 @@ namespace YooAsset if (string.IsNullOrEmpty(packageName)) throw new Exception("Package name is null or empty !"); - if (HasAssetsPackage(packageName)) + if (HasPackage(packageName)) throw new Exception($"Package {packageName} already existed !"); - AssetsPackage assetsPackage = new AssetsPackage(packageName); - _packages.Add(assetsPackage); - return assetsPackage; + ResourcePackage package = new ResourcePackage(packageName); + _packages.Add(package); + return package; } /// /// 获取资源包 /// /// 资源包名称 - public static AssetsPackage GetAssetsPackage(string packageName) + public static ResourcePackage GetPackage(string packageName) { - var package = TryGetAssetsPackage(packageName); + var package = TryGetPackage(packageName); if (package == null) - YooLogger.Warning($"Not found assets package : {packageName}"); + YooLogger.Error($"Not found assets package : {packageName}"); return package; } @@ -120,7 +120,7 @@ namespace YooAsset /// 尝试获取资源包 /// /// 资源包名称 - public static AssetsPackage TryGetAssetsPackage(string packageName) + public static ResourcePackage TryGetPackage(string packageName) { if (_isInitialize == false) throw new Exception($"{nameof(YooAssets)} not initialize !"); @@ -140,7 +140,7 @@ namespace YooAsset /// 检测资源包是否存在 /// /// 资源包名称 - public static bool HasAssetsPackage(string packageName) + public static bool HasPackage(string packageName) { if (_isInitialize == false) throw new Exception($"{nameof(YooAssets)} not initialize !"); diff --git a/Assets/YooAsset/Runtime/YooAssetsExtension.cs b/Assets/YooAsset/Runtime/YooAssetsExtension.cs index c4b2fd0..1e0220b 100644 --- a/Assets/YooAsset/Runtime/YooAssetsExtension.cs +++ b/Assets/YooAsset/Runtime/YooAssetsExtension.cs @@ -8,14 +8,14 @@ namespace YooAsset { public static partial class YooAssets { - private static AssetsPackage _defaultPackage; + private static ResourcePackage _defaultPackage; /// /// 设置默认的资源包 /// - public static void SetDefaultAssetsPackage(AssetsPackage assetsPackage) + public static void SetDefaultPackage(ResourcePackage package) { - _defaultPackage = assetsPackage; + _defaultPackage = package; } #region 资源信息 @@ -286,47 +286,83 @@ namespace YooAsset #region 资源下载 /// - /// 创建补丁下载器,用于下载更新资源标签指定的资源包文件 + /// 创建资源下载器,用于下载当前资源版本所有的资源包文件 + /// + /// 同时下载的最大文件数 + /// 下载失败的重试次数 + public static ResourceDownloaderOperation CreateResourceDownloader(int downloadingMaxNumber, int failedTryAgain) + { + DebugCheckDefaultPackageValid(); + return _defaultPackage.CreateResourceDownloader(downloadingMaxNumber, failedTryAgain); + } + + /// + /// 创建资源下载器,用于下载指定的资源标签关联的资源包文件 /// /// 资源标签 /// 同时下载的最大文件数 /// 下载失败的重试次数 - public static PatchDownloaderOperation CreatePatchDownloader(string tag, int downloadingMaxNumber, int failedTryAgain) + public static ResourceDownloaderOperation CreateResourceDownloader(string tag, int downloadingMaxNumber, int failedTryAgain) { DebugCheckDefaultPackageValid(); - return _defaultPackage.CreatePatchDownloader(new string[] { tag }, downloadingMaxNumber, failedTryAgain); + return _defaultPackage.CreateResourceDownloader(new string[] { tag }, downloadingMaxNumber, failedTryAgain); } /// - /// 创建补丁下载器,用于下载更新资源标签指定的资源包文件 + /// 创建资源下载器,用于下载指定的资源标签列表关联的资源包文件 /// /// 资源标签列表 /// 同时下载的最大文件数 /// 下载失败的重试次数 - public static PatchDownloaderOperation CreatePatchDownloader(string[] tags, int downloadingMaxNumber, int failedTryAgain) + public static ResourceDownloaderOperation CreateResourceDownloader(string[] tags, int downloadingMaxNumber, int failedTryAgain) { DebugCheckDefaultPackageValid(); - return _defaultPackage.CreatePatchDownloader(tags, downloadingMaxNumber, failedTryAgain); + return _defaultPackage.CreateResourceDownloader(tags, downloadingMaxNumber, failedTryAgain); } /// - /// 创建补丁下载器,用于下载更新当前资源版本所有的资源包文件 + /// 创建资源下载器,用于下载指定的资源依赖的资源包文件 /// + /// 资源定位地址 /// 同时下载的最大文件数 /// 下载失败的重试次数 - public static PatchDownloaderOperation CreatePatchDownloader(int downloadingMaxNumber, int failedTryAgain) + public static ResourceDownloaderOperation CreateBundleDownloader(string location, int downloadingMaxNumber, int failedTryAgain) { DebugCheckDefaultPackageValid(); - return _defaultPackage.CreatePatchDownloader(downloadingMaxNumber, failedTryAgain); + return _defaultPackage.CreateBundleDownloader(location, downloadingMaxNumber, failedTryAgain); } /// - /// 创建补丁下载器,用于下载更新指定的资源列表依赖的资源包文件 + /// 创建资源下载器,用于下载指定的资源列表依赖的资源包文件 + /// + /// 资源定位地址列表 + /// 同时下载的最大文件数 + /// 下载失败的重试次数 + public static ResourceDownloaderOperation CreateBundleDownloader(string[] locations, int downloadingMaxNumber, int failedTryAgain) + { + DebugCheckDefaultPackageValid(); + return _defaultPackage.CreateBundleDownloader(locations, downloadingMaxNumber, failedTryAgain); + } + + /// + /// 创建资源下载器,用于下载指定的资源依赖的资源包文件 + /// + /// 资源信息 + /// 同时下载的最大文件数 + /// 下载失败的重试次数 + public static ResourceDownloaderOperation CreateBundleDownloader(AssetInfo assetInfo, int downloadingMaxNumber, int failedTryAgain) + { + DebugCheckDefaultPackageValid(); + return _defaultPackage.CreateBundleDownloader(assetInfo, downloadingMaxNumber, failedTryAgain); + } + + /// + /// 创建资源下载器,用于下载指定的资源列表依赖的资源包文件 /// /// 资源信息列表 /// 同时下载的最大文件数 /// 下载失败的重试次数 - public static PatchDownloaderOperation CreateBundleDownloader(AssetInfo[] assetInfos, int downloadingMaxNumber, int failedTryAgain) + public static ResourceDownloaderOperation CreateBundleDownloader(AssetInfo[] assetInfos, int downloadingMaxNumber, int failedTryAgain) { DebugCheckDefaultPackageValid(); return _defaultPackage.CreateBundleDownloader(assetInfos, downloadingMaxNumber, failedTryAgain); @@ -335,38 +371,38 @@ namespace YooAsset #region 资源解压 /// - /// 创建补丁解压器 + /// 创建内置资源解压器 /// /// 资源标签 /// 同时解压的最大文件数 /// 解压失败的重试次数 - public static PatchUnpackerOperation CreatePatchUnpacker(string tag, int unpackingMaxNumber, int failedTryAgain) + public static ResourceUnpackerOperation CreateResourceUnpacker(string tag, int unpackingMaxNumber, int failedTryAgain) { DebugCheckDefaultPackageValid(); - return _defaultPackage.CreatePatchUnpacker(tag, unpackingMaxNumber, failedTryAgain); + return _defaultPackage.CreateResourceUnpacker(tag, unpackingMaxNumber, failedTryAgain); } /// - /// 创建补丁解压器 + /// 创建内置资源解压器 /// /// 资源标签列表 /// 同时解压的最大文件数 /// 解压失败的重试次数 - public static PatchUnpackerOperation CreatePatchUnpacker(string[] tags, int unpackingMaxNumber, int failedTryAgain) + public static ResourceUnpackerOperation CreateResourceUnpacker(string[] tags, int unpackingMaxNumber, int failedTryAgain) { DebugCheckDefaultPackageValid(); - return _defaultPackage.CreatePatchUnpacker(tags, unpackingMaxNumber, failedTryAgain); + return _defaultPackage.CreateResourceUnpacker(tags, unpackingMaxNumber, failedTryAgain); } /// - /// 创建补丁解压器 + /// 创建内置资源解压器 /// /// 同时解压的最大文件数 /// 解压失败的重试次数 - public static PatchUnpackerOperation CreatePatchUnpacker(int unpackingMaxNumber, int failedTryAgain) + public static ResourceUnpackerOperation CreateResourceUnpacker(int unpackingMaxNumber, int failedTryAgain) { DebugCheckDefaultPackageValid(); - return _defaultPackage.CreatePatchUnpacker(unpackingMaxNumber, failedTryAgain); + return _defaultPackage.CreateResourceUnpacker(unpackingMaxNumber, failedTryAgain); } #endregion @@ -375,7 +411,7 @@ namespace YooAsset private static void DebugCheckDefaultPackageValid() { if (_defaultPackage == null) - throw new Exception($"Default package is null. Please use {nameof(YooAssets.SetDefaultAssetsPackage)} !"); + throw new Exception($"Default package is null. Please use {nameof(YooAssets.SetDefaultPackage)} !"); } #endregion }