123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201 |
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.IO;
- using System.Net;
- using System.Net.Http;
- using System.Threading.Tasks;
- using ET;
- using FairyGUI;
- using UnityEngine;
- using UnityEngine.Networking;
- namespace GFGGame
- {
- public static class MatchingPhotoHelper
- {
- //将图片上传到华为云
- public static async Task<bool> PushToHWCloud(string signUrl, byte[] buffer)
- {
- HttpContent content = new ByteArrayContent(buffer);
- HttpClient httpClient = new HttpClient(new HttpClientHandler() { UseCookies = false });
- HttpResponseMessage response = await httpClient.PutAsync(signUrl, content);
- response.EnsureSuccessStatusCode();
- await response.Content.ReadAsStreamAsync();
- if (response.StatusCode != HttpStatusCode.OK)
- {
- ViewManager.Hide<ModalStatusView>();
- PromptController.Instance.ShowFloatTextPrompt("上传资源失败");
- return false;
- }
- else
- {
- return true;
- }
- }
-
- public static IEnumerator DownloadExt(List<CurRanMatchingPhotoWorksData> list)
- {
- for (int i = 0; i < list.Count; i++)
- {
- CurRanMatchingPhotoWorksData data = list[i];
- if (data == null || data.Ntexture != null || !data.IsUp) continue;
- int count = 0;
- yield return DownloadPictureExt(data, count);
- }
- MatchingCompetitionDataManager.Instance.IsWork = false;
- ET.Log.Debug("Download finish!!!");
- EventAgent.DispatchEvent(ConstMessage.DOWNLOAD_FINISH);
- }
-
- public static IEnumerator Download(List<MatchingPhotoWorksData> list)
- {
- for (int i = 0; i < list.Count; i++)
- {
- MatchingPhotoWorksData data = list[i];
- if (data == null || data.Ntexture != null || !data.IsUp) continue;
- int count = 0;
- yield return DownloadPicture(data, count);
- }
-
- ET.Log.Debug("Download finish!!!");
- EventAgent.DispatchEvent(ConstMessage.DOWNLOAD_FINISH);
- }
- public static IEnumerator Download(List<MatchingWorksData> list)
- {
- for (int i = 0; i < list.Count; i++)
- {
- MatchingWorksData data = list[i];
- if (data == null || data.Ntexture != null) continue;
- int count = 0;
- yield return DownloadPicture(data, count);
- }
- ET.Log.Debug("Download finish!!!");
- EventAgent.DispatchEvent(ConstMessage.DOWNLOAD_FINISH);
- }
- public static IEnumerator Download(MatchingPhotoWorksData list)
- {
- MatchingPhotoWorksData data = list;
- yield return DownloadPicture(data, 1);
- ET.Log.Debug("Download finish!!!");
- EventAgent.DispatchEvent(ConstMessage.DOWNLOAD_FINISH);
- }
-
- private static IEnumerator DownloadPictureExt(CurRanMatchingPhotoWorksData data, int count)
- {
- if (count >= 3)
- {
- PromptController.Instance.ShowFloatTextPrompt("下载失败");
- ET.Log.Error("PoemPhotoData Download failed!!! data:" + JsonUtility.ToJson(data));
- data.Ntexture = null;
- ViewManager.Hide<ModalStatusView>();
- yield break;
- }
- using (UnityWebRequest request = UnityWebRequestTexture.GetTexture(data.JudgingInfo.PictureTempUrl))
- {
- yield return request.SendWebRequest();
- if (request.result == UnityWebRequest.Result.ProtocolError || request.result == UnityWebRequest.Result.ConnectionError)
- {
- ET.Log.Error("Download failed, error code:" + request.result, ",data:" + JsonUtility.ToJson(data));
- count += 1;
- yield return DownloadPictureExt(data, count);
- }
- else
- {
- Texture2D texture = (request.downloadHandler as DownloadHandlerTexture).texture;
- data.Ntexture = new NTexture(texture);
- data.Bytes = texture.EncodeToJPG();
- }
- }
- }
- private static IEnumerator DownloadPicture(MatchingPhotoWorksData data, int count)
- {
- if (count >= 3)
- {
- PromptController.Instance.ShowFloatTextPrompt("下载失败");
- ET.Log.Error("PoemPhotoData Download failed!!! data:" + JsonUtility.ToJson(data));
- data.Ntexture = null;
- ViewManager.Hide<ModalStatusView>();
- yield break;
- }
- using (UnityWebRequest request = UnityWebRequestTexture.GetTexture(data.JudgingInfo.PictureTempUrl))
- {
- yield return request.SendWebRequest();
- if (request.result == UnityWebRequest.Result.ProtocolError || request.result == UnityWebRequest.Result.ConnectionError)
- {
- ET.Log.Error("Download failed, error code:" + request.result, ",data:" + JsonUtility.ToJson(data));
- count += 1;
- yield return DownloadPicture(data, count);
- }
- else
- {
- Texture2D texture = (request.downloadHandler as DownloadHandlerTexture).texture;
- data.Ntexture = new NTexture(texture);
- data.Bytes = texture.EncodeToJPG();
- }
- }
- }
- private static IEnumerator DownloadPicture(MatchingWorksData data, int count)
- {
- if (count >= 3)
- {
- PromptController.Instance.ShowFloatTextPrompt("下载失败");
- ET.Log.Error("PoemPhotoData Download failed!!! data:" + JsonUtility.ToJson(data));
- data.Ntexture = null;
- ViewManager.Hide<ModalStatusView>();
- yield break;
- }
- using (UnityWebRequest request = UnityWebRequestTexture.GetTexture(data.WorksInfo.PictureTempUrl))
- {
- yield return request.SendWebRequest();
- if (request.result == UnityWebRequest.Result.ProtocolError || request.result == UnityWebRequest.Result.ConnectionError)
- {
- ET.Log.Error("Download failed, error code:" + request.result, ",data:" + JsonUtility.ToJson(data));
- count += 1;
- yield return DownloadPicture(data, count);
- }
- else
- {
- Texture2D texture = (request.downloadHandler as DownloadHandlerTexture).texture;
- data.Ntexture = new NTexture(texture);
- data.Bytes = texture.EncodeToJPG();
- }
- }
- }
- public static IEnumerator DownloadMyself(string nTextture)
- {
- yield return DownloadMyPicture(nTextture, 1);
- ET.Log.Debug("Download finish!!!");
- EventAgent.DispatchEvent(ConstMessage.DOWNLOAD_FINISH);
- }
- private static IEnumerator DownloadMyPicture(string nTextture, int count)
- {
- if (count >= 3)
- {
- PromptController.Instance.ShowFloatTextPrompt("下载失败");
- ViewManager.Hide<ModalStatusView>();
- yield break;
- }
- using (UnityWebRequest request = UnityWebRequestTexture.GetTexture(nTextture))
- {
- yield return request.SendWebRequest();
- if (request.result == UnityWebRequest.Result.ProtocolError || request.result == UnityWebRequest.Result.ConnectionError)
- {
- count += 1;
- yield return DownloadMyPicture(nTextture, count);
- }
- else
- {
- Texture2D texture = (request.downloadHandler as DownloadHandlerTexture).texture;
- MatchingCompetitionDataManager.Instance.MyNtextture = new NTexture(texture);
- MatchingCompetitionDataManager.Instance.MyBytes = texture.EncodeToJPG();
- }
- }
- }
- }
- }
|