From 92cba88853eb9f11b1f8e620813e833653953c19 Mon Sep 17 00:00:00 2001 From: Nocye Date: Tue, 20 Jun 2023 16:49:28 +0800 Subject: [PATCH] =?UTF-8?q?add=20=E6=B7=BB=E5=8A=A0=E6=9B=B4=E7=81=B5?= =?UTF-8?q?=E6=B4=BB=E7=9A=84=E6=93=8D=E4=BD=9Ctag=E5=92=8C=E5=8E=9F?= =?UTF-8?q?=E7=94=9F=E6=96=87=E4=BB=B6=E7=9A=84=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Assets/YooAsset/Runtime/MLYEx.meta | 3 + .../MLYEx/ClearTagsCachedFilesOperation.cs | 90 +++++++++++++++++++ .../ClearTagsCachedFilesOperation.cs.meta | 3 + .../PlayMode/EditorSimulateModeImpl.cs | 18 ++++ .../PlayMode/HostPlayModeImpl.cs | 34 +++++++ .../PlayMode/OfflinePlayModeImpl.cs | 9 ++ .../Runtime/PackageSystem/ResourcePackage.cs | 28 +++++- .../Services/Internal/IPlayModeServices.cs | 4 + Assets/YooAsset/Runtime/YooAssetsExtension.cs | 16 ++++ 9 files changed, 204 insertions(+), 1 deletion(-) create mode 100644 Assets/YooAsset/Runtime/MLYEx.meta create mode 100644 Assets/YooAsset/Runtime/MLYEx/ClearTagsCachedFilesOperation.cs create mode 100644 Assets/YooAsset/Runtime/MLYEx/ClearTagsCachedFilesOperation.cs.meta diff --git a/Assets/YooAsset/Runtime/MLYEx.meta b/Assets/YooAsset/Runtime/MLYEx.meta new file mode 100644 index 0000000..6926e1e --- /dev/null +++ b/Assets/YooAsset/Runtime/MLYEx.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: c9fd0b949af8480fa2e882cf65f7b01b +timeCreated: 1687234632 \ No newline at end of file diff --git a/Assets/YooAsset/Runtime/MLYEx/ClearTagsCachedFilesOperation.cs b/Assets/YooAsset/Runtime/MLYEx/ClearTagsCachedFilesOperation.cs new file mode 100644 index 0000000..76a3d23 --- /dev/null +++ b/Assets/YooAsset/Runtime/MLYEx/ClearTagsCachedFilesOperation.cs @@ -0,0 +1,90 @@ +using System.Collections.Generic; + +namespace YooAsset +{ + public class ClearTagsCachedRawFilesOperation : AsyncOperationBase + { + private enum ESteps + { + None, + GetCacheFiles, + ClearCacheFiles, + Done + } + + private ESteps steps; + private List cachedBundles; + private ResourcePackage package; + private string[] tags; + private int clearTotalCount; + + internal ClearTagsCachedRawFilesOperation(ResourcePackage package, string[] tags) + { + this.package = package; + this.tags = tags; + } + + internal override void Start() + { + steps = ESteps.GetCacheFiles; + } + + internal override void Update() + { + if (steps == ESteps.None || steps == ESteps.Done) + { + return; + } + + if (steps == ESteps.GetCacheFiles) + { + var bundles = package.GetCachedTagsRawFiles(tags); + cachedBundles = new List(); + foreach (PackageBundle b in bundles) + { + if (!b.IsRawFile) + { + continue; + } + + if (CacheSystem.IsCached(b.PackageName, b.CacheGUID)) + { + cachedBundles.Add(b); + } + } + + clearTotalCount = cachedBundles.Count; + steps = ESteps.ClearCacheFiles; + } + + if (steps == ESteps.ClearCacheFiles) + { + for (var i = cachedBundles.Count - 1; i >= 0; i--) + { + var b = cachedBundles[i]; + CacheSystem.DiscardFile(b.PackageName, b.CacheGUID); + cachedBundles.RemoveAt(i); + if (OperationSystem.IsBusy) + { + break; + } + } + + if (clearTotalCount == 0) + { + Progress = 1f; + } + else + { + Progress = 1f - (1f * cachedBundles.Count / clearTotalCount); + } + + if (cachedBundles.Count == 0) + { + steps = ESteps.Done; + Status = EOperationStatus.Succeed; + } + } + } + } +} \ No newline at end of file diff --git a/Assets/YooAsset/Runtime/MLYEx/ClearTagsCachedFilesOperation.cs.meta b/Assets/YooAsset/Runtime/MLYEx/ClearTagsCachedFilesOperation.cs.meta new file mode 100644 index 0000000..13fe540 --- /dev/null +++ b/Assets/YooAsset/Runtime/MLYEx/ClearTagsCachedFilesOperation.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 93d20d548161467fb47833ab204f4651 +timeCreated: 1687235010 \ No newline at end of file diff --git a/Assets/YooAsset/Runtime/PackageSystem/PlayMode/EditorSimulateModeImpl.cs b/Assets/YooAsset/Runtime/PackageSystem/PlayMode/EditorSimulateModeImpl.cs index 1fe8f3a..82acded 100644 --- a/Assets/YooAsset/Runtime/PackageSystem/PlayMode/EditorSimulateModeImpl.cs +++ b/Assets/YooAsset/Runtime/PackageSystem/PlayMode/EditorSimulateModeImpl.cs @@ -121,5 +121,23 @@ namespace YooAsset return _activeManifest != null; } #endregion + + #region MLY + + public List GetCachedTagsRawFiles(string[] tags) + { + List result = new List(1000); + foreach (PackageBundle b in _activeManifest.BundleList) + { + if (b.HasTag(tags)) + { + result.Add(b); + } + } + + return result; + } + + #endregion } } \ No newline at end of file diff --git a/Assets/YooAsset/Runtime/PackageSystem/PlayMode/HostPlayModeImpl.cs b/Assets/YooAsset/Runtime/PackageSystem/PlayMode/HostPlayModeImpl.cs index 7eeda25..f88bce1 100644 --- a/Assets/YooAsset/Runtime/PackageSystem/PlayMode/HostPlayModeImpl.cs +++ b/Assets/YooAsset/Runtime/PackageSystem/PlayMode/HostPlayModeImpl.cs @@ -344,5 +344,39 @@ namespace YooAsset return _activeManifest != null; } #endregion + + #region MLY修改 + + public List GetCachedTagsRawFiles(string[] tags) + { + return GetCachedTagsBundle(_activeManifest, tags); + } + + public List GetCachedTagsBundle(PackageManifest manifest,string[] tags) + { + List result = new List(1000); + foreach (PackageBundle b in manifest.BundleList) + { + if (IsBuildinPackageBundle(b)) + { + continue; + } + if (!b.IsRawFile) + { + continue; + } + if (IsCachedPackageBundle(b)) + { + if (b.HasTag(tags)) + { + result.Add(b); + } + } + } + + return result; + } + + #endregion } } \ No newline at end of file diff --git a/Assets/YooAsset/Runtime/PackageSystem/PlayMode/OfflinePlayModeImpl.cs b/Assets/YooAsset/Runtime/PackageSystem/PlayMode/OfflinePlayModeImpl.cs index 20d09af..c19f841 100644 --- a/Assets/YooAsset/Runtime/PackageSystem/PlayMode/OfflinePlayModeImpl.cs +++ b/Assets/YooAsset/Runtime/PackageSystem/PlayMode/OfflinePlayModeImpl.cs @@ -131,5 +131,14 @@ namespace YooAsset return _activeManifest != null; } #endregion + + #region MLy + + public List GetCachedTagsRawFiles(string[] tags) + { + return new List(); + } + + #endregion } } \ No newline at end of file diff --git a/Assets/YooAsset/Runtime/PackageSystem/ResourcePackage.cs b/Assets/YooAsset/Runtime/PackageSystem/ResourcePackage.cs index 10171e3..b31c900 100644 --- a/Assets/YooAsset/Runtime/PackageSystem/ResourcePackage.cs +++ b/Assets/YooAsset/Runtime/PackageSystem/ResourcePackage.cs @@ -334,7 +334,7 @@ namespace YooAsset else return false; } - + /// /// 获取资源信息列表 /// @@ -839,5 +839,31 @@ namespace YooAsset return data; } #endregion + + #region MLY扩展 + + public long GetCachedTagsRawFileSize(string[] tags) + { + var list = _playModeServices.GetCachedTagsRawFiles(tags); + long size = 0; + for (var i = 0; i < list.Count; i++) + { + size += list[i].FileSize; + } + return size; + } + + internal List GetCachedTagsRawFiles(string[] tags) + { + return _playModeServices.GetCachedTagsRawFiles(tags); + } + public ClearTagsCachedRawFilesOperation ClearTagsCacheFilesAsync(string[] tags) + { + DebugCheckInitialize(); + var operation = new ClearTagsCachedRawFilesOperation(this,tags); + OperationSystem.StartOperation(operation); + return operation; + } + #endregion } } \ No newline at end of file diff --git a/Assets/YooAsset/Runtime/Services/Internal/IPlayModeServices.cs b/Assets/YooAsset/Runtime/Services/Internal/IPlayModeServices.cs index d1be3a0..042de3d 100644 --- a/Assets/YooAsset/Runtime/Services/Internal/IPlayModeServices.cs +++ b/Assets/YooAsset/Runtime/Services/Internal/IPlayModeServices.cs @@ -1,4 +1,6 @@  +using System.Collections.Generic; + namespace YooAsset { internal interface IPlayModeServices @@ -36,5 +38,7 @@ namespace YooAsset // 解压相关 ResourceUnpackerOperation CreateResourceUnpackerByAll(int upackingMaxNumber, int failedTryAgain, int timeout); ResourceUnpackerOperation CreateResourceUnpackerByTags(string[] tags, int upackingMaxNumber, int failedTryAgain, int timeout); + + List GetCachedTagsRawFiles(string[] tags); } } \ No newline at end of file diff --git a/Assets/YooAsset/Runtime/YooAssetsExtension.cs b/Assets/YooAsset/Runtime/YooAssetsExtension.cs index 1e0220b..5fb9904 100644 --- a/Assets/YooAsset/Runtime/YooAssetsExtension.cs +++ b/Assets/YooAsset/Runtime/YooAssetsExtension.cs @@ -414,5 +414,21 @@ namespace YooAsset throw new Exception($"Default package is null. Please use {nameof(YooAssets.SetDefaultPackage)} !"); } #endregion + + #region MLY + + public static long GetCachedTagsRawFileSize(string[] tags) + { + DebugCheckDefaultPackageValid(); + return _defaultPackage.GetCachedTagsRawFileSize(tags); + } + + public static ClearTagsCachedRawFilesOperation ClearTagsCacheRawFilesAsync(string[] tags) + { + DebugCheckDefaultPackageValid(); + return _defaultPackage.ClearTagsCacheFilesAsync(tags); + } + + #endregion } } \ No newline at end of file