| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 | using System.Collections;using System.Collections.Generic;using UnityEngine;using UnityEngine.Networking;using Utility;#if UNITY_WEBGL || UNITY_EDITOR  using WeChatWASM;#endifpublic class WXDownload : Singleton<WXDownload>{    public void DownLoad(string url, string fileName, System.Action<bool> finish)    {#if UNITY_WEBGL || UNITY_EDITOR                DownloadFileOption fileOption = new DownloadFileOption();        fileOption.url = url;        fileOption.filePath = GetPluginCachePath() + "/" + fileName;        fileOption.fail = delegate(GeneralCallbackResult result)        {            Debug.LogError(url + "下载失败" + result.errMsg);            finish?.Invoke(false);        };        fileOption.success = delegate(DownloadFileSuccessCallbackResult result)        {            finish?.Invoke(true);            // Debug.Log(url + "下载成功");        };        WX.DownloadFile(fileOption);#elif UNITY_ANDROID        UnityWebRequest unityWebRequest = UnityWebRequest.Get(url);        unityWebRequest.downloadHandler = new DownloadHandlerBuffer();        var unityWebRequestAsyncOperation  =  unityWebRequest.SendWebRequest();        unityWebRequestAsyncOperation.completed += operation =>        {                    if (unityWebRequest.result == UnityWebRequest.Result.Success)            {                finish?.Invoke(true);            }            else            {                Debug.LogError(url + "下载失败" + unityWebRequest.result);                finish?.Invoke(false);            }                 };#endif    }    public string GetCachePath(string url)    { #if UNITY_WEBGL || UNITY_EDITOR               return WX.GetCachePath(url);#elif UNITY_ANDROID        return url;#endif            }    public string GetPluginCachePath()    {#if UNITY_WEBGL || UNITY_EDITOR            return WX.PluginCachePath;#elif UNITY_ANDROID    return Application.persistentDataPath;#endif    }}
 |