Skip to content

Commit

Permalink
refactor : wechat game support
Browse files Browse the repository at this point in the history
提供对微信小游戏缓存的查询接口
  • Loading branch information
gmhevinci committed Apr 11, 2024
1 parent e743a15 commit 370329b
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 16 deletions.
5 changes: 5 additions & 0 deletions Assets/YooAsset/Runtime/InitializeParameters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -150,5 +150,10 @@ public class WebPlayModeParameters : InitializeParameters
/// 内置资源查询服务接口
/// </summary>
public IBuildinQueryServices BuildinQueryServices = null;

/// <summary>
/// 微信缓存查询服务接口
/// </summary>
public IWechatQueryServices WechatQueryServices = null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ internal class WebPlayModeImpl : IPlayMode, IBundleQuery
private ResourceAssist _assist;
private IBuildinQueryServices _buildinQueryServices;
private IRemoteServices _remoteServices;
private IWechatQueryServices _wechatQueryServices;

public readonly string PackageName;
public DownloadManager Download
Expand All @@ -34,11 +35,12 @@ public WebPlayModeImpl(string packageName)
/// <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);
Expand All @@ -65,23 +67,13 @@ private List<BundleInfo> ConvertToDownloadList(List<PackageBundle> downloadList)
}

// 查询相关
#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);
Expand Down
3 changes: 2 additions & 1 deletion Assets/YooAsset/Runtime/ResourcePackage/ResourcePackage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,8 @@ public InitializationOperation InitializeAsync(InitializeParameters parameters)
var initializeParameters = parameters as WebPlayModeParameters;
initializeOperation = webPlayModeImpl.InitializeAsync(assist,
initializeParameters.BuildinQueryServices,
initializeParameters.RemoteServices);
initializeParameters.RemoteServices,
initializeParameters.WechatQueryServices);
}
else
{
Expand Down
15 changes: 15 additions & 0 deletions Assets/YooAsset/Runtime/Services/IWechatQueryServices.cs
Original file line number Diff line number Diff line change
@@ -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);
}
}
11 changes: 11 additions & 0 deletions Assets/YooAsset/Runtime/Services/IWechatQueryServices.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 370329b

Please sign in to comment.