PoemPhotoSProxy.cs 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.Net;
  5. using System.Net.Http;
  6. using ET;
  7. using FairyGUI;
  8. using UnityEngine;
  9. using UnityEngine.Networking;
  10. namespace GFGGame
  11. {
  12. public static class PoemPhotoSProxy
  13. {
  14. //获取玩家所有相册数据协议
  15. public static async ETTask<bool> ReqAllPhotoInfos()
  16. {
  17. S2C_GetAllAlbumInfo response = null;
  18. response = (S2C_GetAllAlbumInfo)await MessageHelper.SendToServer(new C2S_GetAllAlbumInfo());
  19. if (response != null)
  20. {
  21. if (response.Error == ErrorCode.ERR_Success)
  22. {
  23. for (int i = 0; i < response.PictureInfosA.Count; i++)
  24. {
  25. PoemPhotoData photoData = new PoemPhotoData();
  26. photoData.PictureId = response.PictureInfosA[i].PictureId;
  27. photoData.CreationTime = response.PictureInfosA[i].CreationTime;
  28. photoData.ToppingStatus = response.PictureInfosA[i].ToppingStatus;
  29. photoData.LockingStatus = response.PictureInfosA[i].LockingStatus;
  30. photoData.SourceType = response.PictureInfosA[i].SourceType;
  31. photoData.PictureTempUrl = response.PictureInfosA[i].PictureTempUrl;
  32. Timers.inst.StartCoroutine(PictureStorageHelper.DownloadFile(photoData.PictureTempUrl, (Texture2D texture) =>
  33. {
  34. photoData.Bytes = texture.EncodeToJPG();
  35. photoData.Ntexture = new NTexture(texture);
  36. }));
  37. PoemPhotoDataManager.Instance.Add(photoData, (int)PictureSourceType.PersonalAlbum);
  38. }
  39. for (int i = 0; i < response.PictureInfosB.Count; i++)
  40. {
  41. PoemPhotoData photoData = new PoemPhotoData();
  42. photoData.PictureId = response.PictureInfosB[i].PictureId;
  43. photoData.CreationTime = response.PictureInfosB[i].CreationTime;
  44. photoData.ToppingStatus = response.PictureInfosB[i].ToppingStatus;
  45. photoData.LockingStatus = response.PictureInfosB[i].LockingStatus;
  46. photoData.SourceType = response.PictureInfosB[i].SourceType;
  47. photoData.TravelLocationId = response.PictureInfosB[i].TravelLocationId;
  48. photoData.TravelSuitId = response.PictureInfosB[i].TravelSuitId;
  49. photoData.SuitResIndex = response.PictureInfosB[i].TravelSuitResourceIndex;
  50. photoData.PositionIndex = response.PictureInfosB[i].PositionIndex;
  51. PoemPhotoDataManager.Instance.Add(photoData, (int)PictureSourceType.WanShuiQianShan);
  52. }
  53. return true;
  54. }
  55. }
  56. return false;
  57. }
  58. // //获取图片的临时上传地址协议
  59. // public static async ETTask<string[]> ReqTempPictureUrl(int pictureType)
  60. // {
  61. // S2C_GetTempPictureUrl response = null;
  62. // response = (S2C_GetTempPictureUrl)await MessageHelper.SendToServer(new C2S_GetTempPictureUrl() { PictureType = pictureType });
  63. // if (response != null)
  64. // {
  65. // if (response.Error == ErrorCode.ERR_Success)
  66. // {
  67. // return new string[] { response.TempPictureUrl, response.PictureObjectPath };
  68. // }
  69. // }
  70. // else
  71. // {
  72. // ViewManager.Hide<ModalStatusView>();
  73. // PromptController.Instance.ShowFloatTextPrompt("获取上传地址失败");
  74. // }
  75. // return null;
  76. // }
  77. // //将图片上传到华为云
  78. // public static async ETTask<bool> PushToHWCloud(string signUrl, byte[] buffer)
  79. // {
  80. // HttpContent content = new ByteArrayContent(buffer);
  81. // HttpClient httpClient = new HttpClient(new HttpClientHandler() { UseCookies = false });
  82. // HttpResponseMessage response = await httpClient.PutAsync(signUrl, content);
  83. // response.EnsureSuccessStatusCode();
  84. // await response.Content.ReadAsStreamAsync();
  85. // if (response.StatusCode != HttpStatusCode.OK)
  86. // {
  87. // ViewManager.Hide<ModalStatusView>();
  88. // PromptController.Instance.ShowFloatTextPrompt("上传资源失败");
  89. // return false;
  90. // }
  91. // else
  92. // {
  93. // return true;
  94. // }
  95. // }
  96. //保存成功后,添加图片至相册
  97. public static async ETTask<long> ReqAddTophoto(string pictureObjectPath, int sourceType)
  98. {
  99. S2C_AddPicture response = null;
  100. response = (S2C_AddPicture)await MessageHelper.SendToServer(new C2S_AddPicture() { PictureObjectPath = pictureObjectPath, SourceType = sourceType });
  101. ViewManager.Hide<ModalStatusView>();
  102. if (response != null)
  103. {
  104. if (response.Error == ErrorCode.ERR_Success)
  105. {
  106. PoemPhotoData photoData = new PoemPhotoData();
  107. photoData.PictureId = response.PictureInfo.PictureId;
  108. photoData.CreationTime = response.PictureInfo.CreationTime;
  109. photoData.ToppingStatus = response.PictureInfo.ToppingStatus;
  110. photoData.LockingStatus = response.PictureInfo.LockingStatus;
  111. photoData.PictureTempUrl = response.PictureInfo.PictureTempUrl;
  112. PoemPhotoDataManager.Instance.Add(photoData, sourceType);
  113. EventAgent.DispatchEvent(ConstMessage.POEM_PHOTO_INFOS_CHANGE);
  114. PromptController.Instance.ShowFloatTextPrompt("已保存至相册");
  115. return response.PictureInfo.PictureId;
  116. }
  117. }
  118. PromptController.Instance.ShowFloatTextPrompt("存储数据失败");
  119. return 0;
  120. }
  121. // public static IEnumerator DownloadFile(PoemPhotoData poemPhotoData)
  122. // {
  123. // ET.Log.Debug("PictureTempUrl:" + poemPhotoData.PictureTempUrl);
  124. // using (UnityWebRequest request = UnityWebRequestTexture.GetTexture(poemPhotoData.PictureTempUrl))
  125. // {
  126. // yield return request.SendWebRequest();
  127. // if (request.result == UnityWebRequest.Result.ProtocolError || request.result == UnityWebRequest.Result.ConnectionError)
  128. // {
  129. // ET.Log.Debug("Error: " + request.error);
  130. // // while (!request.isDone)
  131. // // {
  132. // DownloadFile(poemPhotoData);
  133. // yield return null;
  134. // // }
  135. // }
  136. // else
  137. // {
  138. // Texture2D texture = (request.downloadHandler as DownloadHandlerTexture).texture;
  139. // poemPhotoData.Bytes = texture.EncodeToJPG();
  140. // poemPhotoData.Ntexture = new NTexture(texture);
  141. // }
  142. // }
  143. // }
  144. //批量删除玩家相册
  145. public static async ETTask<bool> ReqRemovedPhoto(List<long> pictureIds, int sourceType)
  146. {
  147. S2C_RemovedPictures response = null;
  148. response = (S2C_RemovedPictures)await MessageHelper.SendToServer(new C2S_RemovedPictures() { PictureIds = pictureIds });
  149. if (response != null)
  150. {
  151. if (response.Error == ErrorCode.ERR_Success)
  152. {
  153. PoemPhotoDataManager.Instance.Remove(response.PictureIds, sourceType);
  154. EventAgent.DispatchEvent(ConstMessage.POEM_PHOTO_INFOS_CHANGE);
  155. return true;
  156. }
  157. }
  158. return false;
  159. }
  160. //修改图片锁定状态
  161. public static async ETTask<bool> ReqChangeLockingState(long pictureId, bool state, int sourceType)
  162. {
  163. S2C_UpPictureLockingStatus response = null;
  164. response = (S2C_UpPictureLockingStatus)await MessageHelper.SendToServer(new C2S_UpPictureLockingStatus() { PictureId = pictureId, Status = state });
  165. if (response != null)
  166. {
  167. if (response.Error == ErrorCode.ERR_Success)
  168. {
  169. PoemPhotoDataManager.Instance.ChangeLockingState(response.PictureId, response.Status, sourceType);
  170. EventAgent.DispatchEvent(ConstMessage.POEM_PHOTO_INFOS_CHANGE);
  171. return true;
  172. }
  173. }
  174. return false;
  175. }
  176. //修改图片置顶状态
  177. public static async ETTask<bool> ReqChangeToppingState(long pictureId, bool state, int sourceType)
  178. {
  179. S2C_UpPictureToppingStatus response = null;
  180. response = (S2C_UpPictureToppingStatus)await MessageHelper.SendToServer(new C2S_UpPictureToppingStatus() { PictureId = pictureId, Status = state });
  181. if (response != null)
  182. {
  183. if (response.Error == ErrorCode.ERR_Success)
  184. {
  185. PoemPhotoDataManager.Instance.ChangeToppingState(response.PictureId, response.Status, sourceType);
  186. EventAgent.DispatchEvent(ConstMessage.POEM_PHOTO_INFOS_CHANGE);
  187. return true;
  188. }
  189. }
  190. return false;
  191. }
  192. }
  193. }