diff --git a/Assets/YooAsset/Runtime/PackageSystem/PlayMode/OfflinePlayModeImpl.cs b/Assets/YooAsset/Runtime/PackageSystem/PlayMode/OfflinePlayModeImpl.cs index 20d09af..c304e61 100644 --- a/Assets/YooAsset/Runtime/PackageSystem/PlayMode/OfflinePlayModeImpl.cs +++ b/Assets/YooAsset/Runtime/PackageSystem/PlayMode/OfflinePlayModeImpl.cs @@ -20,6 +20,22 @@ namespace YooAsset return operation; } + // 解压相关 + private List ConvertToUnpackList(List unpackList) + { + List result = new List(unpackList.Count); + foreach (var packageBundle in unpackList) + { + var bundleInfo = ConvertToUnpackInfo(packageBundle); + result.Add(bundleInfo); + } + return result; + } + private BundleInfo ConvertToUnpackInfo(PackageBundle packageBundle) + { + return ManifestTools.GetUnpackInfo(packageBundle); + } + #region IPlayModeServices接口 public PackageManifest ActiveManifest { @@ -37,6 +53,11 @@ namespace YooAsset { } + private bool IsCachedPackageBundle(PackageBundle packageBundle) + { + return CacheSystem.IsCached(packageBundle.PackageName, packageBundle.CacheGUID); + } + UpdatePackageVersionOperation IPlayModeServices.UpdatePackageVersionAsync(bool appendTimeTicks, int timeout) { var operation = new OfflinePlayModeUpdatePackageVersionOperation(); @@ -71,11 +92,48 @@ namespace YooAsset ResourceUnpackerOperation IPlayModeServices.CreateResourceUnpackerByAll(int upackingMaxNumber, int failedTryAgain, int timeout) { - return ResourceUnpackerOperation.CreateEmptyUnpacker(upackingMaxNumber, failedTryAgain, timeout); + List unpcakList = GetUnpackListByAll(_activeManifest); + var operation = new ResourceUnpackerOperation(unpcakList, upackingMaxNumber, failedTryAgain, timeout); + return operation; } + private List GetUnpackListByAll(PackageManifest manifest) + { + List downloadList = new List(1000); + foreach (var packageBundle in manifest.BundleList) + { + // 忽略缓存文件 + if (IsCachedPackageBundle(packageBundle)) + continue; + + downloadList.Add(packageBundle); + } + + return ConvertToUnpackList(downloadList); + } + ResourceUnpackerOperation IPlayModeServices.CreateResourceUnpackerByTags(string[] tags, int upackingMaxNumber, int failedTryAgain, int timeout) { - return ResourceUnpackerOperation.CreateEmptyUnpacker(upackingMaxNumber, failedTryAgain, timeout); + List unpcakList = GetUnpackListByTags(_activeManifest, tags); + var operation = new ResourceUnpackerOperation(unpcakList, upackingMaxNumber, failedTryAgain, timeout); + return operation; + } + private List GetUnpackListByTags(PackageManifest manifest, string[] tags) + { + List downloadList = new List(1000); + foreach (var packageBundle in manifest.BundleList) + { + // 忽略缓存文件 + if (IsCachedPackageBundle(packageBundle)) + continue; + + // 查询DLC资源 + if (packageBundle.HasTag(tags)) + { + downloadList.Add(packageBundle); + } + } + + return ConvertToUnpackList(downloadList); } #endregion