/// <summary> /// /// </summary> /// <param name="url"></param> /// <param name="webRequestGetEvent"></param> /// <param name="SavePath">如果为""则不需要保存</param> /// <param name="isReturnPath">默认是返回内容</param> /// <returns></returns> public IEnumerator RealWebRequest(string url, WebRequestNetTextureEvent webRequestGetEvent, string savePath = "") { webRequest = UnityWebRequestTexture.GetTexture(url); httpRequestCount += 1; yield return(webRequest.SendWebRequest()); if (webRequest.error == null || webRequest.error == "") { Texture2D texture2D = DownloadHandlerTexture.GetContent(webRequest); if (savePath != null && savePath != "") { FileHelper.CreatFile(savePath, texture2D.EncodeToPNG()); } webRequestGetEvent(texture2D, savePath, DownStatus.Sucess, ""); webRequest = null; } else { webRequest = null; DownManager.Instance.DebugDownError(httpRequestCount, url, webRequest.error); if (httpRequestCount <= 3) { IEnumeratorTool.StartCoroutine(RealWebRequest(url, webRequestGetEvent)); } else { if (webRequestGetEvent != null) { webRequestGetEvent.Invoke(default(Texture2D), savePath, DownStatus.Fail, webRequest.error); } } } }
public void StartNetTexture(string url, WebRequestNetTextureEvent webRequestGetEvent, string savePath = "") { if (JudgeNetworkState()) { HttpNetTextureTool httpTool = new HttpNetTextureTool(); httpTool.StartWebRequest(url, webRequestGetEvent, savePath); } else { webRequestGetEvent(default(Texture2D), "", DownStatus.NoNetwork, ""); } }
public void StartWebRequest(string url, WebRequestNetTextureEvent webRequestGetEvent, string savePath = "") { httpRequestCount = 0; IEnumeratorTool.StartCoroutine(RealWebRequest(url, webRequestGetEvent)); }