WXDownload.cs 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. // using System.Collections;
  2. // using System.Collections.Generic;
  3. // using UnityEngine;
  4. // using UnityEngine.Networking;
  5. // using Utility;
  6. // #if UNITY_WEBGL || UNITY_EDITOR
  7. // using WeChatWASM;
  8. // #endif
  9. //
  10. // public class WXDownload : Singleton<WXDownload>
  11. // {
  12. // public void DownLoad(string url, string fileName, System.Action<bool> finish)
  13. // {
  14. // #if UNITY_WEBGL || UNITY_EDITOR
  15. // DownloadFileOption fileOption = new DownloadFileOption();
  16. // fileOption.url = url;
  17. // fileOption.filePath = GetPluginCachePath() + "/" + fileName;
  18. // fileOption.fail = delegate(GeneralCallbackResult result)
  19. // {
  20. // Debug.LogError(url + "下载失败" + result.errMsg);
  21. // finish?.Invoke(false);
  22. // };
  23. // fileOption.success = delegate(DownloadFileSuccessCallbackResult result)
  24. // {
  25. // finish?.Invoke(true);
  26. // // Debug.Log(url + "下载成功");
  27. // };
  28. // WX.DownloadFile(fileOption);
  29. // #elif UNITY_ANDROID
  30. // UnityWebRequest unityWebRequest = UnityWebRequest.Get(url);
  31. // unityWebRequest.downloadHandler = new DownloadHandlerBuffer();
  32. // var unityWebRequestAsyncOperation = unityWebRequest.SendWebRequest();
  33. // unityWebRequestAsyncOperation.completed += operation =>
  34. // {
  35. //
  36. // if (unityWebRequest.result == UnityWebRequest.Result.Success)
  37. // {
  38. // finish?.Invoke(true);
  39. // }
  40. // else
  41. // {
  42. // Debug.LogError(url + "下载失败" + unityWebRequest.result);
  43. // finish?.Invoke(false);
  44. // }
  45. //
  46. // };
  47. // #endif
  48. // }
  49. // public string GetCachePath(string url)
  50. // {
  51. // #if UNITY_WEBGL || UNITY_EDITOR
  52. // return WX.GetCachePath(url);
  53. // #elif UNITY_ANDROID
  54. // return url;
  55. // #endif
  56. //
  57. // }
  58. //
  59. // public string GetPluginCachePath()
  60. // {
  61. // #if UNITY_WEBGL || UNITY_EDITOR
  62. // return WX.PluginCachePath;
  63. // #elif UNITY_ANDROID
  64. // return Application.persistentDataPath;
  65. // #endif
  66. // }
  67. // }