From 370329b07d376c302eff4a57c6f519287cf1b5cb Mon Sep 17 00:00:00 2001 From: hevinci Date: Thu, 11 Apr 2024 19:51:34 +0800 Subject: [PATCH] refactor : wechat game support MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 提供对微信小游戏缓存的查询接口 --- .../YooAsset/Runtime/InitializeParameters.cs | 5 +++++ .../PlayMode/WebPlayModeImpl.cs | 22 ++++++------------- .../ResourcePackage/ResourcePackage.cs | 3 ++- .../Runtime/Services/IWechatQueryServices.cs | 15 +++++++++++++ .../Services/IWechatQueryServices.cs.meta | 11 ++++++++++ 5 files changed, 40 insertions(+), 16 deletions(-) create mode 100644 Assets/YooAsset/Runtime/Services/IWechatQueryServices.cs create mode 100644 Assets/YooAsset/Runtime/Services/IWechatQueryServices.cs.meta diff --git a/Assets/YooAsset/Runtime/InitializeParameters.cs b/Assets/YooAsset/Runtime/InitializeParameters.cs index 8925dbb..b66f40b 100644 --- a/Assets/YooAsset/Runtime/InitializeParameters.cs +++ b/Assets/YooAsset/Runtime/InitializeParameters.cs @@ -150,5 +150,10 @@ namespace YooAsset /// 内置资源查询服务接口 /// public IBuildinQueryServices BuildinQueryServices = null; + + /// + /// 微信缓存查询服务接口 + /// + public IWechatQueryServices WechatQueryServices = null; } } \ No newline at end of file diff --git a/Assets/YooAsset/Runtime/ResourcePackage/PlayMode/WebPlayModeImpl.cs b/Assets/YooAsset/Runtime/ResourcePackage/PlayMode/WebPlayModeImpl.cs index de07307..5b9cc70 100644 --- a/Assets/YooAsset/Runtime/ResourcePackage/PlayMode/WebPlayModeImpl.cs +++ b/Assets/YooAsset/Runtime/ResourcePackage/PlayMode/WebPlayModeImpl.cs @@ -10,6 +10,7 @@ namespace YooAsset private ResourceAssist _assist; private IBuildinQueryServices _buildinQueryServices; private IRemoteServices _remoteServices; + private IWechatQueryServices _wechatQueryServices; public readonly string PackageName; public DownloadManager Download @@ -34,11 +35,12 @@ namespace YooAsset /// /// 异步初始化 /// - public InitializationOperation InitializeAsync(ResourceAssist assist, IBuildinQueryServices buildinQueryServices, IRemoteServices remoteServices) + public InitializationOperation InitializeAsync(ResourceAssist assist, IBuildinQueryServices buildinQueryServices, IRemoteServices remoteServices, IWechatQueryServices wechatQueryServices) { _assist = assist; _buildinQueryServices = buildinQueryServices; _remoteServices = remoteServices; + _wechatQueryServices = wechatQueryServices; var operation = new WebPlayModeInitializationOperation(this); OperationSystem.StartOperation(PackageName, operation); @@ -65,23 +67,13 @@ namespace YooAsset } // 查询相关 -#if UNITY_WECHAT_GAME - private WeChatWASM.WXFileSystemManager _wxFileSystemMgr; private bool IsCachedPackageBundle(PackageBundle packageBundle) { - if (_wxFileSystemMgr == null) - _wxFileSystemMgr = WeChatWASM.WX.GetFileSystemManager(); - string filePath = WeChatWASM.WX.env.USER_DATA_PATH + packageBundle.FileName; - string result = _wxFileSystemMgr.AccessSync(filePath); - return result.Equals("access:ok"); + if (_wechatQueryServices != null) + return _wechatQueryServices.Query(PackageName, packageBundle.FileName, packageBundle.FileCRC); + else + return false; } -#else - private bool IsCachedPackageBundle(PackageBundle packageBundle) - { - return false; - } -#endif - private bool IsBuildinPackageBundle(PackageBundle packageBundle) { return _buildinQueryServices.Query(PackageName, packageBundle.FileName, packageBundle.FileCRC); diff --git a/Assets/YooAsset/Runtime/ResourcePackage/ResourcePackage.cs b/Assets/YooAsset/Runtime/ResourcePackage/ResourcePackage.cs index 301591f..0629bdb 100644 --- a/Assets/YooAsset/Runtime/ResourcePackage/ResourcePackage.cs +++ b/Assets/YooAsset/Runtime/ResourcePackage/ResourcePackage.cs @@ -184,7 +184,8 @@ namespace YooAsset var initializeParameters = parameters as WebPlayModeParameters; initializeOperation = webPlayModeImpl.InitializeAsync(assist, initializeParameters.BuildinQueryServices, - initializeParameters.RemoteServices); + initializeParameters.RemoteServices, + initializeParameters.WechatQueryServices); } else { diff --git a/Assets/YooAsset/Runtime/Services/IWechatQueryServices.cs b/Assets/YooAsset/Runtime/Services/IWechatQueryServices.cs new file mode 100644 index 0000000..c225bdb --- /dev/null +++ b/Assets/YooAsset/Runtime/Services/IWechatQueryServices.cs @@ -0,0 +1,15 @@ + +namespace YooAsset +{ + public interface IWechatQueryServices + { + /// + /// 查询是否为微信缓存的资源文件 + /// + /// 包裹名称 + /// 文件名称(包含文件的后缀格式) + /// 文件哈希值 + /// 返回查询结果 + bool Query(string packageName, string fileName, string fileCRC); + } +} \ No newline at end of file diff --git a/Assets/YooAsset/Runtime/Services/IWechatQueryServices.cs.meta b/Assets/YooAsset/Runtime/Services/IWechatQueryServices.cs.meta new file mode 100644 index 0000000..e7455b4 --- /dev/null +++ b/Assets/YooAsset/Runtime/Services/IWechatQueryServices.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: e6b28ce9425f5eb4f972dcda9fd864f3 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: