refactor : wechat game support

提供对微信小游戏缓存的查询接口
pull/286/head
hevinci 2024-04-11 19:51:34 +08:00
parent e743a15fbc
commit 370329b07d
5 changed files with 40 additions and 16 deletions

View File

@ -150,5 +150,10 @@ namespace YooAsset
/// 内置资源查询服务接口
/// </summary>
public IBuildinQueryServices BuildinQueryServices = null;
/// <summary>
/// 微信缓存查询服务接口
/// </summary>
public IWechatQueryServices WechatQueryServices = null;
}
}

View File

@ -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
/// <summary>
/// 异步初始化
/// </summary>
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);

View File

@ -184,7 +184,8 @@ namespace YooAsset
var initializeParameters = parameters as WebPlayModeParameters;
initializeOperation = webPlayModeImpl.InitializeAsync(assist,
initializeParameters.BuildinQueryServices,
initializeParameters.RemoteServices);
initializeParameters.RemoteServices,
initializeParameters.WechatQueryServices);
}
else
{

View File

@ -0,0 +1,15 @@

namespace YooAsset
{
public interface IWechatQueryServices
{
/// <summary>
/// 查询是否为微信缓存的资源文件
/// </summary>
/// <param name="packageName">包裹名称</param>
/// <param name="fileName">文件名称(包含文件的后缀格式)</param>
/// <param name="fileCRC">文件哈希值</param>
/// <returns>返回查询结果</returns>
bool Query(string packageName, string fileName, string fileCRC);
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: e6b28ce9425f5eb4f972dcda9fd864f3
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: