diff --git a/Assets/YooAsset/Runtime/AssetSystem/Loader/AssetBundleFileLoader.cs b/Assets/YooAsset/Runtime/AssetSystem/Loader/AssetBundleFileLoader.cs index 1f0a8df..0ec9208 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 = HostPlayModeImpl.ConvertToUnpackInfo(MainBundleInfo.Bundle); + var bundleInfo = PatchManifestTools.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 7b4d393..cf6fa78 100644 --- a/Assets/YooAsset/Runtime/AssetSystem/Loader/RawBundleFileLoader.cs +++ b/Assets/YooAsset/Runtime/AssetSystem/Loader/RawBundleFileLoader.cs @@ -93,7 +93,7 @@ namespace YooAsset if (_steps == ESteps.Unpack) { int failedTryAgain = 1; - var bundleInfo = HostPlayModeImpl.ConvertToUnpackInfo(MainBundleInfo.Bundle); + var bundleInfo = PatchManifestTools.GetUnpackInfo(MainBundleInfo.Bundle); _unpacker = DownloadSystem.BeginDownload(bundleInfo, failedTryAgain); _steps = ESteps.CheckUnpack; } diff --git a/Assets/YooAsset/Runtime/PatchSystem/Operations/Internal/DownloadManifestOperation.cs b/Assets/YooAsset/Runtime/PatchSystem/Operations/Internal/DownloadManifestOperation.cs index 2d68804..0707fe7 100644 --- a/Assets/YooAsset/Runtime/PatchSystem/Operations/Internal/DownloadManifestOperation.cs +++ b/Assets/YooAsset/Runtime/PatchSystem/Operations/Internal/DownloadManifestOperation.cs @@ -12,7 +12,7 @@ namespace YooAsset } private static int RequestCount = 0; - private readonly HostPlayModeImpl _impl; + private readonly IRemoteServices _remoteServices; private readonly string _packageName; private readonly string _packageVersion; private readonly int _timeout; @@ -20,9 +20,9 @@ namespace YooAsset private UnityWebFileRequester _downloader2; private ESteps _steps = ESteps.None; - internal DownloadManifestOperation(HostPlayModeImpl impl, string packageName, string packageVersion, int timeout) + internal DownloadManifestOperation(IRemoteServices remoteServices, string packageName, string packageVersion, int timeout) { - _impl = impl; + _remoteServices = remoteServices; _packageName = packageName; _packageVersion = packageVersion; _timeout = timeout; @@ -103,9 +103,9 @@ namespace YooAsset { // 轮流返回请求地址 if (RequestCount % 2 == 0) - return _impl.GetPatchDownloadFallbackURL(fileName); + return _remoteServices.GetRemoteFallbackURL(fileName); else - return _impl.GetPatchDownloadMainURL(fileName); + return _remoteServices.GetRemoteMainURL(fileName); } } } \ No newline at end of file diff --git a/Assets/YooAsset/Runtime/PatchSystem/Operations/Internal/QueryRemotePackageVersionOperation.cs b/Assets/YooAsset/Runtime/PatchSystem/Operations/Internal/QueryRemotePackageVersionOperation.cs index 8988138..ff7e93f 100644 --- a/Assets/YooAsset/Runtime/PatchSystem/Operations/Internal/QueryRemotePackageVersionOperation.cs +++ b/Assets/YooAsset/Runtime/PatchSystem/Operations/Internal/QueryRemotePackageVersionOperation.cs @@ -12,7 +12,7 @@ namespace YooAsset } private static int RequestCount = 0; - private readonly HostPlayModeImpl _impl; + private readonly IRemoteServices _remoteServices; private readonly string _packageName; private readonly bool _appendTimeTicks; private readonly int _timeout; @@ -25,9 +25,9 @@ namespace YooAsset public string PackageVersion { private set; get; } - public QueryRemotePackageVersionOperation(HostPlayModeImpl impl, string packageName, bool appendTimeTicks, int timeout) + public QueryRemotePackageVersionOperation(IRemoteServices remoteServices, string packageName, bool appendTimeTicks, int timeout) { - _impl = impl; + _remoteServices = remoteServices; _packageName = packageName; _appendTimeTicks = appendTimeTicks; _timeout = timeout; @@ -89,9 +89,9 @@ namespace YooAsset // 轮流返回请求地址 if (RequestCount % 2 == 0) - url = _impl.GetPatchDownloadFallbackURL(fileName); + url = _remoteServices.GetRemoteFallbackURL(fileName); else - url = _impl.GetPatchDownloadMainURL(fileName); + url = _remoteServices.GetRemoteMainURL(fileName); // 在URL末尾添加时间戳 if (_appendTimeTicks) diff --git a/Assets/YooAsset/Runtime/PatchSystem/PatchBundle.cs b/Assets/YooAsset/Runtime/PatchSystem/PatchBundle.cs index fe21a4f..4b6b7de 100644 --- a/Assets/YooAsset/Runtime/PatchSystem/PatchBundle.cs +++ b/Assets/YooAsset/Runtime/PatchSystem/PatchBundle.cs @@ -120,7 +120,7 @@ namespace YooAsset { _packageName = packageName; _cacheKey = $"{packageName}-{FileHash}"; - _fileName = PatchManifest.CreateBundleFileName(nameStype, BundleName, FileHash, IsRawFile); + _fileName = PatchManifestTools.CreateBundleFileName(nameStype, BundleName, FileHash, IsRawFile); } /// diff --git a/Assets/YooAsset/Runtime/PatchSystem/PatchManifest.cs b/Assets/YooAsset/Runtime/PatchSystem/PatchManifest.cs index f1667e7..44ce4d5 100644 --- a/Assets/YooAsset/Runtime/PatchSystem/PatchManifest.cs +++ b/Assets/YooAsset/Runtime/PatchSystem/PatchManifest.cs @@ -292,28 +292,6 @@ namespace YooAsset } } - /// - /// 生成Bundle文件的正式名称 - /// - public static string CreateBundleFileName(int nameStyle, string bundleName, string fileHash, bool isRawFile) - { - if (nameStyle == 1) //HashName - { - string fileExtension = isRawFile ? YooAssetSettingsData.Setting.RawFileVariant : YooAssetSettingsData.Setting.AssetBundleFileVariant; - return StringUtility.Format("{0}.{1}", fileHash, fileExtension); - } - else if (nameStyle == 4) //BundleName_HashName - { - string fileName = bundleName.Remove(bundleName.LastIndexOf('.')); - string fileExtension = isRawFile ? YooAssetSettingsData.Setting.RawFileVariant : YooAssetSettingsData.Setting.AssetBundleFileVariant; - return StringUtility.Format("{0}_{1}.{2}", fileName, fileHash, fileExtension); - } - else - { - throw new NotImplementedException($"Invalid name style : {nameStyle}"); - } - } - #region 调试方法 [Conditional("DEBUG")] private void DebugCheckLocation(string location) diff --git a/Assets/YooAsset/Runtime/PatchSystem/PatchManifestTools.cs b/Assets/YooAsset/Runtime/PatchSystem/PatchManifestTools.cs index 45fbd51..35790fa 100644 --- a/Assets/YooAsset/Runtime/PatchSystem/PatchManifestTools.cs +++ b/Assets/YooAsset/Runtime/PatchSystem/PatchManifestTools.cs @@ -151,5 +151,38 @@ namespace YooAsset return manifest; } + + /// + /// 生成Bundle文件的正式名称 + /// + public static string CreateBundleFileName(int nameStyle, string bundleName, string fileHash, bool isRawFile) + { + if (nameStyle == 1) //HashName + { + string fileExtension = isRawFile ? YooAssetSettingsData.Setting.RawFileVariant : YooAssetSettingsData.Setting.AssetBundleFileVariant; + return StringUtility.Format("{0}.{1}", fileHash, fileExtension); + } + else if (nameStyle == 4) //BundleName_HashName + { + string fileName = bundleName.Remove(bundleName.LastIndexOf('.')); + string fileExtension = isRawFile ? YooAssetSettingsData.Setting.RawFileVariant : YooAssetSettingsData.Setting.AssetBundleFileVariant; + 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/HostPlayModeImpl.cs b/Assets/YooAsset/Runtime/PatchSystem/PlayMode/HostPlayModeImpl.cs index a8bbf9a..85f19fa 100644 --- a/Assets/YooAsset/Runtime/PatchSystem/PlayMode/HostPlayModeImpl.cs +++ b/Assets/YooAsset/Runtime/PatchSystem/PlayMode/HostPlayModeImpl.cs @@ -4,7 +4,7 @@ using System.Collections.Generic; namespace YooAsset { - internal class HostPlayModeImpl : IPlayModeServices, IBundleServices + internal class HostPlayModeImpl : IPlayModeServices, IBundleServices, IRemoteServices { private PatchManifest _activeManifest; @@ -31,16 +31,6 @@ namespace YooAsset return operation; } - // WEB相关 - public string GetPatchDownloadMainURL(string fileName) - { - return $"{_defaultHostServer}/{fileName}"; - } - public string GetPatchDownloadFallbackURL(string fileName) - { - return $"{_fallbackHostServer}/{fileName}"; - } - // 下载相关 private List ConvertToDownloadList(List downloadList) { @@ -54,8 +44,8 @@ namespace YooAsset } private BundleInfo ConvertToDownloadInfo(PatchBundle patchBundle) { - string remoteMainURL = GetPatchDownloadMainURL(patchBundle.FileName); - string remoteFallbackURL = GetPatchDownloadFallbackURL(patchBundle.FileName); + string remoteMainURL = GetRemoteMainURL(patchBundle.FileName); + string remoteFallbackURL = GetRemoteFallbackURL(patchBundle.FileName); BundleInfo bundleInfo = new BundleInfo(patchBundle, BundleInfo.ELoadMode.LoadFromRemote, remoteMainURL, remoteFallbackURL); return bundleInfo; } @@ -71,14 +61,22 @@ namespace YooAsset } return result; } - public static BundleInfo ConvertToUnpackInfo(PatchBundle patchBundle) + private BundleInfo ConvertToUnpackInfo(PatchBundle patchBundle) { - // 注意:我们把流加载路径指定为远端下载地址 - string streamingPath = PathHelper.ConvertToWWWPath(patchBundle.StreamingFilePath); - BundleInfo bundleInfo = new BundleInfo(patchBundle, BundleInfo.ELoadMode.LoadFromStreaming, streamingPath, streamingPath); - return bundleInfo; + return PatchManifestTools.GetUnpackInfo(patchBundle); } + #region IRemoteServices接口 + public string GetRemoteMainURL(string fileName) + { + return $"{_defaultHostServer}/{fileName}"; + } + public string GetRemoteFallbackURL(string fileName) + { + return $"{_fallbackHostServer}/{fileName}"; + } + #endregion + #region IPlayModeServices接口 public PatchManifest ActiveManifest { diff --git a/Assets/YooAsset/Runtime/Services/IRemoteServices.cs b/Assets/YooAsset/Runtime/Services/IRemoteServices.cs new file mode 100644 index 0000000..54a4d40 --- /dev/null +++ b/Assets/YooAsset/Runtime/Services/IRemoteServices.cs @@ -0,0 +1,9 @@ + +namespace YooAsset +{ + internal interface IRemoteServices + { + string GetRemoteMainURL(string fileName); + string GetRemoteFallbackURL(string fileName); + } +} \ No newline at end of file diff --git a/Assets/YooAsset/Runtime/Services/IRemoteServices.cs.meta b/Assets/YooAsset/Runtime/Services/IRemoteServices.cs.meta new file mode 100644 index 0000000..e8c8a6c --- /dev/null +++ b/Assets/YooAsset/Runtime/Services/IRemoteServices.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 55b92092303a8d44280c107e6c5a8379 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: