From 37624b33d1a23064f8642fd9c8661404765a04ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=98=BF=E6=9E=AB?= <7997747+suxf@users.noreply.github.com> Date: Mon, 10 Feb 2025 00:43:53 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=BE=AE=E4=BF=A1=E5=B0=8F=E6=B8=B8?= =?UTF-8?q?=E6=88=8F=E6=96=87=E4=BB=B6=E7=B3=BB=E7=BB=9F=E7=BC=93=E5=AD=98?= =?UTF-8?q?=E6=9F=A5=E8=AF=A2=E6=9C=BA=E5=88=B6=E4=B8=8D=E7=94=9F=E6=95=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../WechatFileSystem/WechatFileSystem.cs | 28 +++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/Assets/YooAsset/Samples~/Extension Sample/Runtime/ExtensionFileSystem/WechatFileSystem/WechatFileSystem.cs b/Assets/YooAsset/Samples~/Extension Sample/Runtime/ExtensionFileSystem/WechatFileSystem/WechatFileSystem.cs index c1059b22..62043fd5 100644 --- a/Assets/YooAsset/Samples~/Extension Sample/Runtime/ExtensionFileSystem/WechatFileSystem/WechatFileSystem.cs +++ b/Assets/YooAsset/Samples~/Extension Sample/Runtime/ExtensionFileSystem/WechatFileSystem/WechatFileSystem.cs @@ -1,4 +1,4 @@ -#if UNITY_WEBGL && WEIXINMINIGAME +#if UNITY_WEBGL && WEIXINMINIGAME using System; using System.Collections.Generic; using System.Linq; @@ -57,6 +57,7 @@ internal class WechatFileSystem : IFileSystem private readonly Dictionary _cacheFilePaths = new Dictionary(10000); private WXFileSystemManager _fileSystemMgr; private string _wxCacheRoot = string.Empty; + private string _recordsFilePath = string.Empty; /// /// 包裹名称 @@ -176,6 +177,7 @@ internal class WechatFileSystem : IFileSystem { PackageName = packageName; _wxCacheRoot = rootDirectory; + _recordsFilePath = PathUtility.Combine(FileRoot, "__GAME_FILE_CACHE", "cache_records"); if (string.IsNullOrEmpty(_wxCacheRoot)) { @@ -190,6 +192,24 @@ internal class WechatFileSystem : IFileSystem } _fileSystemMgr = WX.GetFileSystemManager(); + + // 读取本地文件缓存记录 + if (CheckCacheFileExist(_recordsFilePath)) + { + string recordText = _fileSystemMgr.ReadFileSync(_recordsFilePath, "utf8"); + if (string.IsNullOrEmpty(recordText) == false) + { + string[] records = recordText.Split(',', StringSplitOptions.RemoveEmptyEntries); + foreach (var record in records) + { + _recorders.Add(record); + } + } + } + else + { + _fileSystemMgr.WriteFileSync(_recordsFilePath, string.Empty); + } } public virtual void OnUpdate() { @@ -276,6 +296,7 @@ internal class WechatFileSystem : IFileSystem } _recorders.Add(filePath); + _fileSystemMgr.AppendFileSync(_recordsFilePath, filePath + ","); return true; } public void TryRecordBundle(PackageBundle bundle) @@ -284,11 +305,13 @@ internal class WechatFileSystem : IFileSystem if (_recorders.Contains(filePath) == false) { _recorders.Add(filePath); + _fileSystemMgr.AppendFileSync(_recordsFilePath, filePath + ","); } } public void ClearAllRecords() { _recorders.Clear(); + _fileSystemMgr.WriteFileSync(_recordsFilePath, string.Empty); } public void ClearRecord(string filePath) { @@ -296,7 +319,8 @@ internal class WechatFileSystem : IFileSystem { _recorders.Remove(filePath); } + //TODO: 这里没做记录移除,因为耗时,后续可以看情况添加 } #endregion } -#endif \ No newline at end of file +#endif