From e0427d3062748027b29fa4e6a1829052fad2d69a Mon Sep 17 00:00:00 2001 From: jcakCheng Date: Fri, 13 Sep 2024 11:44:40 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BE=AE=E4=BF=A1=E5=B0=8F=E6=B8=B8=E6=88=8F?= =?UTF-8?q?=EF=BC=8CPackageVersion=E8=AF=B7=E6=B1=82url=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=5FappendTimeTicks;=E4=BF=AE=E6=94=B9unusedCache=E8=B7=AF?= =?UTF-8?q?=E5=BE=84=E5=88=A4=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Assets/YooAsset/Runtime/YooAssets.cs | 1 + .../WXFSClearUnusedBundleFilesAsync.cs | 10 ++++----- .../WXFSRequestPackageVersionOperation.cs | 6 +++-- .../RequestWechatPackageVersionOperation.cs | 16 +++++++++++--- .../WechatFileSystem/WechatFileSystem.cs | 2 +- .../FsmNode/FsmClearPackageCache.cs | 22 +++++++++---------- 6 files changed, 33 insertions(+), 24 deletions(-) diff --git a/Assets/YooAsset/Runtime/YooAssets.cs b/Assets/YooAsset/Runtime/YooAssets.cs index e8a90e0..0a841f5 100644 --- a/Assets/YooAsset/Runtime/YooAssets.cs +++ b/Assets/YooAsset/Runtime/YooAssets.cs @@ -13,6 +13,7 @@ namespace YooAsset private static readonly List _packages = new List(); public const string DefaultPackageVersion_Key = "DefaultPackageVersion_Key"; + public const string DefaultPcakageVersion = "100000"; /// /// 是否已经初始化 diff --git a/Assets/YooAsset/Samples~/Extension Sample/Runtime/WechatFileSystem/Operation/WXFSClearUnusedBundleFilesAsync.cs b/Assets/YooAsset/Samples~/Extension Sample/Runtime/WechatFileSystem/Operation/WXFSClearUnusedBundleFilesAsync.cs index c3384c9..3a34cbf 100644 --- a/Assets/YooAsset/Samples~/Extension Sample/Runtime/WechatFileSystem/Operation/WXFSClearUnusedBundleFilesAsync.cs +++ b/Assets/YooAsset/Samples~/Extension Sample/Runtime/WechatFileSystem/Operation/WXFSClearUnusedBundleFilesAsync.cs @@ -49,7 +49,6 @@ internal class WXFSClearUnusedBundleFilesAsync : FSClearUnusedBundleFilesOperati if(_fileData != null && _fileData.Length > 0 && !string.IsNullOrEmpty(_packageHash)) { _steps = ESteps.VerifyFileData; - Debug.Log($"===_packageHash==={_packageHash}"); } else { @@ -57,8 +56,6 @@ internal class WXFSClearUnusedBundleFilesAsync : FSClearUnusedBundleFilesOperati Status = EOperationStatus.Failed; Error = "Failed to load cache package manifest file!"; } - - //YooLogger.Log($"Found unused cache files count : {_unusedFileTotalCount}"); } if(_steps == ESteps.VerifyFileData) @@ -165,12 +162,13 @@ internal class WXFSClearUnusedBundleFilesAsync : FSClearUnusedBundleFilesOperati private void LoadManifestInfo() { var packageName = _fileSystem.PackageName; - _lastPackageVersion = WX.StorageGetStringSync(YooAssets.DefaultPackageVersion_Key, "100000"); + _lastPackageVersion = WX.StorageGetStringSync(YooAssets.DefaultPackageVersion_Key, YooAssets.DefaultPcakageVersion); Debug.Log($"==========取出本地数据版本文件成功==={_lastPackageVersion}"); if (!string.IsNullOrEmpty(_lastPackageVersion)) { var cacheManifestHashPath = GetUnuseCachePathByBundleName(YooAssetSettingsData.GetPackageHashFileName(packageName, _lastPackageVersion)); var cacheManifestPath = GetUnuseCachePathByBundleName(YooAssetSettingsData.GetManifestBinaryFileName(packageName, _lastPackageVersion)); + if(string.IsNullOrEmpty(cacheManifestHashPath) || string.IsNullOrEmpty(cacheManifestPath)) { return; } _packageHash = _fileSystem.ReadFileText(cacheManifestHashPath); _fileData = _fileSystem.ReadFileData(cacheManifestPath); @@ -179,8 +177,8 @@ internal class WXFSClearUnusedBundleFilesAsync : FSClearUnusedBundleFilesOperati private string GetUnuseCachePathByBundleName(string fileName) { - var path = $"StreamingAssets/WebGL/v{WechatFileSystemCreater.AppVersion}/{fileName}"; - return WX.GetCachePath(path); + var filePath = $"StreamingAssets/WebGL/{fileName}"; + return WX.GetCachePath(filePath); } } #endif \ No newline at end of file diff --git a/Assets/YooAsset/Samples~/Extension Sample/Runtime/WechatFileSystem/Operation/WXFSRequestPackageVersionOperation.cs b/Assets/YooAsset/Samples~/Extension Sample/Runtime/WechatFileSystem/Operation/WXFSRequestPackageVersionOperation.cs index 0ca200d..e9f90fe 100644 --- a/Assets/YooAsset/Samples~/Extension Sample/Runtime/WechatFileSystem/Operation/WXFSRequestPackageVersionOperation.cs +++ b/Assets/YooAsset/Samples~/Extension Sample/Runtime/WechatFileSystem/Operation/WXFSRequestPackageVersionOperation.cs @@ -11,14 +11,16 @@ internal class WXFSRequestPackageVersionOperation : FSRequestPackageVersionOpera } private readonly WechatFileSystem _fileSystem; + private readonly bool _appendTimeTicks; private readonly int _timeout; private RequestWechatPackageVersionOperation _requestWebPackageVersionOp; private ESteps _steps = ESteps.None; - internal WXFSRequestPackageVersionOperation(WechatFileSystem fileSystem, int timeout) + internal WXFSRequestPackageVersionOperation(WechatFileSystem fileSystem, bool appendTimeTicks, int timeout) { _fileSystem = fileSystem; + _appendTimeTicks = appendTimeTicks; _timeout = timeout; } internal override void InternalOnStart() @@ -34,7 +36,7 @@ internal class WXFSRequestPackageVersionOperation : FSRequestPackageVersionOpera { if (_requestWebPackageVersionOp == null) { - _requestWebPackageVersionOp = new RequestWechatPackageVersionOperation(_fileSystem, _timeout); + _requestWebPackageVersionOp = new RequestWechatPackageVersionOperation(_fileSystem, _appendTimeTicks, _timeout); OperationSystem.StartOperation(_fileSystem.PackageName, _requestWebPackageVersionOp); } diff --git a/Assets/YooAsset/Samples~/Extension Sample/Runtime/WechatFileSystem/Operation/internal/RequestWechatPackageVersionOperation.cs b/Assets/YooAsset/Samples~/Extension Sample/Runtime/WechatFileSystem/Operation/internal/RequestWechatPackageVersionOperation.cs index f4856ca..75fc169 100644 --- a/Assets/YooAsset/Samples~/Extension Sample/Runtime/WechatFileSystem/Operation/internal/RequestWechatPackageVersionOperation.cs +++ b/Assets/YooAsset/Samples~/Extension Sample/Runtime/WechatFileSystem/Operation/internal/RequestWechatPackageVersionOperation.cs @@ -12,6 +12,7 @@ internal class RequestWechatPackageVersionOperation : AsyncOperationBase private readonly WechatFileSystem _fileSystem; private readonly int _timeout; + private readonly bool _appendTimeTicks; private UnityWebTextRequestOperation _webTextRequestOp; private int _requestCount = 0; private ESteps _steps = ESteps.None; @@ -22,9 +23,10 @@ internal class RequestWechatPackageVersionOperation : AsyncOperationBase public string PackageVersion { private set; get; } - public RequestWechatPackageVersionOperation(WechatFileSystem fileSystem, int timeout) + public RequestWechatPackageVersionOperation(WechatFileSystem fileSystem, bool appendTimeTicks, int timeout) { _fileSystem = fileSystem; + _appendTimeTicks = appendTimeTicks; _timeout = timeout; } internal override void InternalOnStart() @@ -78,11 +80,19 @@ internal class RequestWechatPackageVersionOperation : AsyncOperationBase private string GetRequestURL(string fileName) { + string url; + // 轮流返回请求地址 if (_requestCount % 2 == 0) - return _fileSystem.RemoteServices.GetRemoteMainURL(fileName); + url = _fileSystem.RemoteServices.GetRemoteMainURL(fileName); else - return _fileSystem.RemoteServices.GetRemoteFallbackURL(fileName); + url = _fileSystem.RemoteServices.GetRemoteFallbackURL(fileName); + + // 在URL末尾添加时间戳 + if (_appendTimeTicks) + return $"{url}?{System.DateTime.UtcNow.Ticks}"; + else + return url; } } #endif \ No newline at end of file diff --git a/Assets/YooAsset/Samples~/Extension Sample/Runtime/WechatFileSystem/WechatFileSystem.cs b/Assets/YooAsset/Samples~/Extension Sample/Runtime/WechatFileSystem/WechatFileSystem.cs index 6e5db09..13d8d74 100644 --- a/Assets/YooAsset/Samples~/Extension Sample/Runtime/WechatFileSystem/WechatFileSystem.cs +++ b/Assets/YooAsset/Samples~/Extension Sample/Runtime/WechatFileSystem/WechatFileSystem.cs @@ -112,7 +112,7 @@ internal class WechatFileSystem : IFileSystem } public virtual FSRequestPackageVersionOperation RequestPackageVersionAsync(bool appendTimeTicks, int timeout) { - var operation = new WXFSRequestPackageVersionOperation(this, timeout); + var operation = new WXFSRequestPackageVersionOperation(this, appendTimeTicks, timeout); OperationSystem.StartOperation(PackageName, operation); return operation; } diff --git a/Assets/YooAsset/Samples~/Space Shooter/GameScript/Runtime/PatchLogic/FsmNode/FsmClearPackageCache.cs b/Assets/YooAsset/Samples~/Space Shooter/GameScript/Runtime/PatchLogic/FsmNode/FsmClearPackageCache.cs index cee5bab..f14b35d 100644 --- a/Assets/YooAsset/Samples~/Space Shooter/GameScript/Runtime/PatchLogic/FsmNode/FsmClearPackageCache.cs +++ b/Assets/YooAsset/Samples~/Space Shooter/GameScript/Runtime/PatchLogic/FsmNode/FsmClearPackageCache.cs @@ -34,19 +34,17 @@ internal class FsmClearPackageCache : IStateNode { #if UNITY_WEBGL && WEIXINMINIGAME - //删除旧的资源清单文件和哈希文件 - if (WX.StorageHasKeySync(YooAssets.DefaultPackageVersion_Key)) + //删除旧的资源清单文件和哈希文件 + if (WX.StorageHasKeySync(YooAssets.DefaultPackageVersion_Key)) + { + var packageName = (string)_machine.GetBlackboardValue("PackageName"); + var packageVersion = (string)_machine.GetBlackboardValue("PackageVersion"); + var lastPackageVersion = WX.StorageGetStringSync(YooAssets.DefaultPackageVersion_Key, ""); + if (lastPackageVersion != packageVersion) { - var packageName = (string)_machine.GetBlackboardValue("PackageName"); - var packageVersion = (string)_machine.GetBlackboardValue("PackageVersion"); - var lastPackageVersion = WX.StorageGetStringSync(YooAssets.DefaultPackageVersion_Key, ""); - if (!string.IsNullOrEmpty(lastPackageVersion) && lastPackageVersion != packageVersion) - { - WX.StorageSetStringSync(YooAssets.DefaultPackageVersion_Key, packageVersion); - Debug.Log($"==========本地数据版本文件设置成功==={packageVersion}"); - - } - } + WX.StorageSetStringSync(YooAssets.DefaultPackageVersion_Key, packageVersion); + } + } #endif _machine.ChangeState(); }