WXDownload.cs 921 B

123456789101112131415161718192021222324252627282930
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using Utility;
  5. using WeChatWASM;
  6. public class WXDownload : Singleton<WXDownload>
  7. {
  8. public void DownLoad(string url, string fileName, System.Action<bool> finish)
  9. {
  10. DownloadFileOption fileOption = new DownloadFileOption();
  11. fileOption.url = url;
  12. fileOption.filePath = WX.PluginCachePath + "/" + fileName;
  13. fileOption.fail = delegate(GeneralCallbackResult result)
  14. {
  15. Debug.LogError(url + "下载失败" + result.errMsg);
  16. finish?.Invoke(false);
  17. };
  18. fileOption.success = delegate(DownloadFileSuccessCallbackResult result)
  19. {
  20. finish?.Invoke(true);
  21. // Debug.Log(url + "下载成功");
  22. };
  23. WX.DownloadFile(fileOption);
  24. }
  25. public string GetCachePath(string url)
  26. {
  27. return WX.GetCachePath(url);
  28. }
  29. }