From 1b04ead6b4025c2787a0316d237933ebe8a6365d 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:44:52 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E6=8A=96=E9=9F=B3=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 --- .../TiktokFileSystem/TiktokFileSystem.cs | 32 +++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/Assets/YooAsset/Samples~/Extension Sample/Runtime/ExtensionFileSystem/TiktokFileSystem/TiktokFileSystem.cs b/Assets/YooAsset/Samples~/Extension Sample/Runtime/ExtensionFileSystem/TiktokFileSystem/TiktokFileSystem.cs index 3fc0c8e1..b3f65e3f 100644 --- a/Assets/YooAsset/Samples~/Extension Sample/Runtime/ExtensionFileSystem/TiktokFileSystem/TiktokFileSystem.cs +++ b/Assets/YooAsset/Samples~/Extension Sample/Runtime/ExtensionFileSystem/TiktokFileSystem/TiktokFileSystem.cs @@ -1,4 +1,4 @@ -#if UNITY_WEBGL && DOUYINMINIGAME +#if UNITY_WEBGL && DOUYINMINIGAME using System.Collections.Generic; using UnityEngine; using YooAsset; @@ -57,6 +57,7 @@ internal class TiktokFileSystem : IFileSystem private readonly Dictionary _cacheFilePaths = new Dictionary(10000); private TTFileSystemManager _fileSystemMgr; private string _ttCacheRoot = string.Empty; + private string _recordsFilePath = string.Empty; /// /// 包裹名称 @@ -160,6 +161,7 @@ internal class TiktokFileSystem : IFileSystem { PackageName = packageName; _ttCacheRoot = rootDirectory; + _recordsFilePath = PathUtility.Combine(FileRoot, "__GAME_FILE_CACHE", "cache_records"); if (string.IsNullOrEmpty(_ttCacheRoot)) { @@ -174,6 +176,24 @@ internal class TiktokFileSystem : IFileSystem } _fileSystemMgr = TT.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() { @@ -259,6 +279,9 @@ internal class TiktokFileSystem : IFileSystem } _recorders.Add(filePath); + // 抖音没有AppendFileSync方法,所以这里直接写入,等后面增加这个方法再修改 + _fileSystemMgr.WriteFileSync(_recordsFilePath, string.Join(",", _recorders)); + // _fileSystemMgr.AppendFileSync(_recordsFilePath, filePath + ","); return true; } public void TryRecordBundle(PackageBundle bundle) @@ -267,11 +290,15 @@ internal class TiktokFileSystem : IFileSystem if (_recorders.Contains(filePath) == false) { _recorders.Add(filePath); + // 抖音没有AppendFileSync方法,所以这里直接写入,等后面增加这个方法再修改 + _fileSystemMgr.WriteFileSync(_recordsFilePath, string.Join(",", _recorders)); + // _fileSystemMgr.AppendFileSync(_recordsFilePath, filePath + ","); } } public void ClearAllRecords() { _recorders.Clear(); + _fileSystemMgr.WriteFileSync(_recordsFilePath, string.Empty); } public void ClearRecord(string filePath) { @@ -279,7 +306,8 @@ internal class TiktokFileSystem : IFileSystem { _recorders.Remove(filePath); } + //TODO: 这里没做记录移除,因为耗时,后续可以看情况添加 } #endregion } -#endif \ No newline at end of file +#endif