From 0627641845cdc83ae1dcaa1f5a0c9ecc51108623 Mon Sep 17 00:00:00 2001 From: jcakCheng Date: Mon, 9 Sep 2024 20:33:28 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=BE=AE=E4=BF=A1=E5=B0=8F?= =?UTF-8?q?=E6=B8=B8=E6=88=8F=E5=88=A0=E9=99=A4=E7=BC=93=E5=AD=98=E6=A0=B9?= =?UTF-8?q?=E7=9B=AE=E5=BD=95=E4=B9=8B=E5=90=8E=E9=87=8D=E5=90=AF=E5=B0=8F?= =?UTF-8?q?=E6=B8=B8=E6=88=8F=E9=80=BB=E8=BE=91=EF=BC=8CWX.CleanAllFileCac?= =?UTF-8?q?he?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../WechatFileSystem/WechatFileSystem.cs | 52 +++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/Assets/YooAsset/Samples~/Extension Sample/Runtime/WechatFileSystem/WechatFileSystem.cs b/Assets/YooAsset/Samples~/Extension Sample/Runtime/WechatFileSystem/WechatFileSystem.cs index 349b641..6e5db09 100644 --- a/Assets/YooAsset/Samples~/Extension Sample/Runtime/WechatFileSystem/WechatFileSystem.cs +++ b/Assets/YooAsset/Samples~/Extension Sample/Runtime/WechatFileSystem/WechatFileSystem.cs @@ -247,6 +247,58 @@ internal class WechatFileSystem : IFileSystem string result = _wxFileSystemMgr.AccessSync(filePath); return result.Equals("access:ok"); } +#region 调用微信小游戏接口删除缓存文件目录下所有文件 + public void ClearAllCacheFile() + { +#if !UNITY_EDITOR && UNITY_WEBGL && WEIXINMINIGAME + ShowModalOption showModalOp = new ShowModalOption(); + showModalOp.title = "提示"; + showModalOp.content = "是否确定要清理缓存并重启"; + showModalOp.confirmText = "确定"; + showModalOp.cancelText = "取消"; + showModalOp.complete = (GeneralCallbackResult callResult) => { Debug.Log($"complete==={callResult.errMsg}"); }; + showModalOp.fail = (GeneralCallbackResult callResult) => { Debug.Log($"fail==={callResult.errMsg}"); }; + showModalOp.success = (ShowModalSuccessCallbackResult callResult) => + { + if(callResult.confirm) + RestartMiniGame(); + }; + WX.ShowModal(showModalOp); +#endif + } + + /// + /// 微信小游戏清除缓存并且重启小游戏 + /// 参考小游戏=>出发吧麦芬 + /// + private void RestartMiniGame() + { + WX.CleanAllFileCache((bool isOk) => + { + RestartMiniProgramOption restartMini = new RestartMiniProgramOption(); + restartMini.complete = RestartMiniComplete; + restartMini.fail = RestartMiniFailComplete; + restartMini.success = RestartMiniSuccComplete; + WX.RestartMiniProgram(restartMini); + }); + } + + private void RestartMiniComplete(GeneralCallbackResult result) + { + Debug.Log($"RestartMiniComplete:{result.errMsg}"); + } + + private void RestartMiniFailComplete(GeneralCallbackResult result) + { + Debug.Log($"RestartMiniFailComplete:{result.errMsg}"); + } + + private void RestartMiniSuccComplete(GeneralCallbackResult result) + { + Debug.Log($"RestartMiniSuccComplete:{result.errMsg}"); + } + +#endregion #region 内部方法 private string GetCacheFileLoadPath(PackageBundle bundle) {