diff --git a/Assets/YooAsset/Runtime/CacheSystem/CacheSystem.cs b/Assets/YooAsset/Runtime/CacheSystem/CacheSystem.cs index 3f17277..7b812d8 100644 --- a/Assets/YooAsset/Runtime/CacheSystem/CacheSystem.cs +++ b/Assets/YooAsset/Runtime/CacheSystem/CacheSystem.cs @@ -23,6 +23,15 @@ namespace YooAsset _cachedDic.Clear(); } + /// + /// 获取缓存文件总数 + /// + public static int GetCachedFilesCount(string packageName) + { + var cache = GetOrCreateCache(packageName); + return cache.GetCachedFilesCount(); + } + /// /// 查询是否为验证文件 /// diff --git a/Assets/YooAsset/Runtime/CacheSystem/Operations/Internal/FindCacheFilesOperation.cs b/Assets/YooAsset/Runtime/CacheSystem/Operations/Internal/FindCacheFilesOperation.cs index 6be1a7c..4149c7a 100644 --- a/Assets/YooAsset/Runtime/CacheSystem/Operations/Internal/FindCacheFilesOperation.cs +++ b/Assets/YooAsset/Runtime/CacheSystem/Operations/Internal/FindCacheFilesOperation.cs @@ -101,17 +101,21 @@ namespace YooAsset if (isFindItem == false) break; - var fileFoder = _bundleFilesEnumerator.Current; - string cacheGUID = fileFoder.Name; - if (CacheSystem.IsCached(_packageName, cacheGUID)) - continue; + var rootFoder = _bundleFilesEnumerator.Current; + var childDirectories = rootFoder.GetDirectories(); + foreach(var chidDirectory in childDirectories) + { + string cacheGUID = chidDirectory.Name; + if (CacheSystem.IsCached(_packageName, cacheGUID)) + continue; - // 创建验证元素类 - string fileRootPath = fileFoder.FullName; - string dataFilePath = $"{fileRootPath}/{ YooAssetSettings.CacheBundleDataFileName}"; - string infoFilePath = $"{fileRootPath}/{ YooAssetSettings.CacheBundleInfoFileName}"; - VerifyElement element = new VerifyElement(_packageName, cacheGUID, fileRootPath, dataFilePath, infoFilePath); - VerifyElements.Add(element); + // 创建验证元素类 + string fileRootPath = chidDirectory.FullName; + string dataFilePath = $"{fileRootPath}/{ YooAssetSettings.CacheBundleDataFileName}"; + string infoFilePath = $"{fileRootPath}/{ YooAssetSettings.CacheBundleInfoFileName}"; + VerifyElement element = new VerifyElement(_packageName, cacheGUID, fileRootPath, dataFilePath, infoFilePath); + VerifyElements.Add(element); + } if (OperationSystem.IsBusy) break; @@ -131,32 +135,35 @@ namespace YooAsset if (isFindItem == false) break; - var fileFoder = _rawFilesEnumerator.Current; - string cacheGUID = fileFoder.Name; - if (CacheSystem.IsCached(_packageName, cacheGUID)) - continue; - - // 获取数据文件的后缀名 - string dataFileExtension = string.Empty; - var fileInfos = fileFoder.GetFiles(); - foreach (var fileInfo in fileInfos) + var rootFoder = _rawFilesEnumerator.Current; + var childDirectories = rootFoder.GetDirectories(); + foreach (var chidDirectory in childDirectories) { - if (fileInfo.Extension == ".temp") + string cacheGUID = chidDirectory.Name; + if (CacheSystem.IsCached(_packageName, cacheGUID)) continue; - if (fileInfo.Name.StartsWith(YooAssetSettings.CacheBundleDataFileName)) + // 获取数据文件的后缀名 + string dataFileExtension = string.Empty; + var fileInfos = chidDirectory.GetFiles(); + foreach (var fileInfo in fileInfos) { - dataFileExtension = fileInfo.Extension; - break; + if (fileInfo.Extension == ".temp") + continue; + if (fileInfo.Name.StartsWith(YooAssetSettings.CacheBundleDataFileName)) + { + dataFileExtension = fileInfo.Extension; + break; + } } - } - // 创建验证元素类 - string fileRootPath = fileFoder.FullName; - string dataFilePath = $"{fileRootPath}/{ YooAssetSettings.CacheBundleDataFileName}{dataFileExtension}"; - string infoFilePath = $"{fileRootPath}/{ YooAssetSettings.CacheBundleInfoFileName}"; - VerifyElement element = new VerifyElement(_packageName, cacheGUID, fileRootPath, dataFilePath, infoFilePath); - VerifyElements.Add(element); + // 创建验证元素类 + string fileRootPath = chidDirectory.FullName; + string dataFilePath = $"{fileRootPath}/{ YooAssetSettings.CacheBundleDataFileName}{dataFileExtension}"; + string infoFilePath = $"{fileRootPath}/{ YooAssetSettings.CacheBundleInfoFileName}"; + VerifyElement element = new VerifyElement(_packageName, cacheGUID, fileRootPath, dataFilePath, infoFilePath); + VerifyElements.Add(element); + } if (OperationSystem.IsBusy) break; diff --git a/Assets/YooAsset/Runtime/CacheSystem/Operations/PackageCachingOperation.cs b/Assets/YooAsset/Runtime/CacheSystem/Operations/PackageCachingOperation.cs index 8f9f55a..c8c9777 100644 --- a/Assets/YooAsset/Runtime/CacheSystem/Operations/PackageCachingOperation.cs +++ b/Assets/YooAsset/Runtime/CacheSystem/Operations/PackageCachingOperation.cs @@ -63,6 +63,9 @@ namespace YooAsset // 注意:总是返回成功 _steps = ESteps.Done; Status = EOperationStatus.Succeed; + + int totalCount = CacheSystem.GetCachedFilesCount(_packageName); + YooLogger.Log($"Package '{_packageName}' cached files count : {totalCount}"); } } } diff --git a/Assets/YooAsset/Runtime/CacheSystem/PackageCache.cs b/Assets/YooAsset/Runtime/CacheSystem/PackageCache.cs index be42a41..1ddaab7 100644 --- a/Assets/YooAsset/Runtime/CacheSystem/PackageCache.cs +++ b/Assets/YooAsset/Runtime/CacheSystem/PackageCache.cs @@ -44,6 +44,14 @@ namespace YooAsset _wrappers.Clear(); } + /// + /// 获取缓存文件总数 + /// + public int GetCachedFilesCount() + { + return _wrappers.Count; + } + /// /// 查询缓存记录 /// diff --git a/Assets/YooAsset/Runtime/PatchSystem/PatchBundle.cs b/Assets/YooAsset/Runtime/PatchSystem/PatchBundle.cs index 7e6e041..af97c95 100644 --- a/Assets/YooAsset/Runtime/PatchSystem/PatchBundle.cs +++ b/Assets/YooAsset/Runtime/PatchSystem/PatchBundle.cs @@ -71,15 +71,16 @@ namespace YooAsset if (string.IsNullOrEmpty(_cachedDataFilePath) == false) return _cachedDataFilePath; + string folderName = FileHash.Substring(0, 2); if (IsRawFile) { string cacheRoot = PersistentHelper.GetCachedRawFileFolderPath(PackageName); - _cachedDataFilePath = $"{cacheRoot}/{CacheGUID}/{YooAssetSettings.CacheBundleDataFileName}{_fileExtension}"; + _cachedDataFilePath = $"{cacheRoot}/{folderName}/{CacheGUID}/{YooAssetSettings.CacheBundleDataFileName}{_fileExtension}"; } else { string cacheRoot = PersistentHelper.GetCachedBundleFileFolderPath(PackageName); - _cachedDataFilePath = $"{cacheRoot}/{CacheGUID}/{YooAssetSettings.CacheBundleDataFileName}"; + _cachedDataFilePath = $"{cacheRoot}/{folderName}/{CacheGUID}/{YooAssetSettings.CacheBundleDataFileName}"; } return _cachedDataFilePath; } @@ -96,15 +97,16 @@ namespace YooAsset if (string.IsNullOrEmpty(_cachedInfoFilePath) == false) return _cachedInfoFilePath; + string folderName = FileHash.Substring(0, 2); if (IsRawFile) { string cacheRoot = PersistentHelper.GetCachedRawFileFolderPath(PackageName); - _cachedInfoFilePath = $"{cacheRoot}/{CacheGUID}/{YooAssetSettings.CacheBundleInfoFileName}"; + _cachedInfoFilePath = $"{cacheRoot}/{folderName}/{CacheGUID}/{YooAssetSettings.CacheBundleInfoFileName}"; } else { string cacheRoot = PersistentHelper.GetCachedBundleFileFolderPath(PackageName); - _cachedInfoFilePath = $"{cacheRoot}/{CacheGUID}/{YooAssetSettings.CacheBundleInfoFileName}"; + _cachedInfoFilePath = $"{cacheRoot}/{folderName}/{CacheGUID}/{YooAssetSettings.CacheBundleInfoFileName}"; } return _cachedInfoFilePath; }