zhaoyang 2 年之前
父节点
当前提交
b7cd891da2

+ 48 - 71
GameClient/Assets/Game/HotUpdate/ServerProxy/PoemPhotoSProxy.cs

@@ -1,9 +1,12 @@
+using System.Collections;
 using System.Collections.Generic;
 using System.IO;
 using System.Net;
 using ET;
+using FairyGUI;
 using GFGGame;
-
+using UnityEngine;
+using UnityEngine.Networking;
 
 namespace GFGGame
 {
@@ -28,10 +31,7 @@ namespace GFGGame
                         photoData.LockingStatus = response.PictureInfosA[i].LockingStatus;
                         photoData.PictureName = response.PictureInfosA[i].PictureName;
                         photoData.PictureTempUrl = response.PictureInfosA[i].PictureTempUrl;
-                        byte[] bytes = DownloadFile(response.PictureInfosA[i].PictureTempUrl);
-                        photoData.Bytes = bytes;
-                        // photoData.Ntexture = PoemPhotoDataManager.Instance.BytesToTexture2D(bytes); ;
-
+                        Timers.inst.StartCoroutine(DownloadFile(photoData));
                         PoemPhotoDataManager.Instance.Add(photoData, (int)PictureSourceType.PersonalAlbum);
                     }
                     for (int i = 0; i < response.PictureInfosB.Count; i++)
@@ -44,10 +44,7 @@ namespace GFGGame
                         photoData.LockingStatus = response.PictureInfosB[i].LockingStatus;
                         photoData.PictureName = response.PictureInfosB[i].PictureName;
                         photoData.PictureTempUrl = response.PictureInfosB[i].PictureTempUrl;
-                        byte[] bytes = DownloadFile(response.PictureInfosB[i].PictureTempUrl);
-                        photoData.Bytes = bytes;
-                        // photoData.Ntexture = PoemPhotoDataManager.Instance.BytesToTexture2D(bytes); ;
-
+                        Timers.inst.StartCoroutine(DownloadFile(photoData));
                         PoemPhotoDataManager.Instance.Add(photoData, (int)PictureSourceType.WanShuiQianShan);
                     }
                     return true;
@@ -59,17 +56,13 @@ namespace GFGGame
         //获取图片的临时上传地址协议
         public static async ETTask<string[]> ReqTempPictureUrl(int pictureType)
         {
-            ET.Log.Debug("zoya000");
             S2C_GetTempPictureUrl response = null;
             response = (S2C_GetTempPictureUrl)await MessageHelper.SendToServer(new C2S_GetTempPictureUrl() { PictureType = pictureType });
-            ET.Log.Debug("zoya111");
 
             if (response != null)
             {
                 if (response.Error == ErrorCode.ERR_Success)
                 {
-                    ET.Log.Debug("zoya222");
-
                     return new string[] { response.TempPictureUrl, response.PictureObjectPath };
                 }
             }
@@ -79,7 +72,6 @@ namespace GFGGame
         //将图片上传到华为云
         public static string PushToHWCloud(string signUrl, byte[] buffer)
         {
-            ET.Log.Debug("zoya333" + buffer);
 
             // 使用PUT请求上传对象
             HttpWebRequest webRequest = WebRequest.Create(signUrl) as HttpWebRequest;
@@ -96,33 +88,26 @@ namespace GFGGame
             HttpWebResponse webResponse = null;
             try
             {
-                ET.Log.Debug("zoya444");
-
                 webResponse = webRequest.GetResponse() as HttpWebResponse;
                 return webResponse.StatusCode.ToString();
             }
             catch (WebException ex)
             {
-                ET.Log.Debug("zoya555");
-
                 webResponse = ex.Response as HttpWebResponse;
                 return "";
             }
         }
         //保存成功后,添加图片至相册
-        public static async ETTask<bool> ReqAddTophoto(string pictureObjectPath, int sourceType)
+        public static async ETTask<long> ReqAddTophoto(string pictureObjectPath, int sourceType)
         {
-            ET.Log.Debug("zoya666");
 
             S2C_AddPicture response = null;
             response = (S2C_AddPicture)await MessageHelper.SendToServer(new C2S_AddPicture() { PictureObjectPath = pictureObjectPath, SourceType = sourceType });
-            ET.Log.Debug("zoya777");
 
             if (response != null)
             {
                 if (response.Error == ErrorCode.ERR_Success)
                 {
-                    ET.Log.Debug("zoya888");
 
                     PoemPhotoData photoData = new PoemPhotoData();
                     photoData.PictureId = response.PictureInfo.PictureId;
@@ -132,66 +117,58 @@ namespace GFGGame
                     photoData.LockingStatus = response.PictureInfo.LockingStatus;
                     photoData.PictureName = response.PictureInfo.PictureName;
                     photoData.PictureTempUrl = response.PictureInfo.PictureTempUrl;
-                    ET.Log.Debug("zoya999" + response.PictureInfo.PictureTempUrl);
-
-                    byte[] bytes = DownloadFile(photoData.PictureTempUrl);
-                    ET.Log.Debug("zoyafff");
-                    photoData.Bytes = bytes;
-
                     PoemPhotoDataManager.Instance.Add(photoData, sourceType);
-                    ET.Log.Debug("zoyajjj");
-
-
                     EventAgent.DispatchEvent(ConstMessage.POEM_PHOTO_INFOS_CHANGE);
                     PromptController.Instance.ShowFloatTextPrompt("已保存至相册");
-                    return true;
+                    return response.PictureInfo.PictureId;
                 }
             }
-            return false;
+            return 0;
         }
-        public static byte[] DownloadFile(string URL)
+        public static IEnumerator DownloadFile(PoemPhotoData poemPhotoData)
         {
-            try
+            using (UnityWebRequest request = UnityWebRequestTexture.GetTexture(poemPhotoData.PictureTempUrl))
             {
-                ET.Log.Debug("zoyaaaa" + URL);
-
-                HttpWebRequest webRequest = HttpWebRequest.Create(URL) as HttpWebRequest;
-                webRequest.Method = "GET";
-                ET.Log.Debug("zoyabbb+Method:" + webRequest.Method);
-
-                HttpWebResponse webResponse = webRequest.GetResponse() as HttpWebResponse;
-                ET.Log.Debug("zoyabbb" + webResponse);
-
-                System.IO.Stream st = webResponse.GetResponseStream();
-                ET.Log.Debug("zoyabbb+st:" + st);
-
-                byte[] bytes;
-                using (var ms = new MemoryStream())
-                {
-                    st.CopyTo(ms);
-                    bytes = ms.ToArray();
-                }
-                ET.Log.Debug("zoyaccc");
-
-                st.Close();
-                webResponse.Close();
-                webRequest.Abort();
-                ET.Log.Debug("zoyaddd");
-
-                return bytes;
+                yield return request.SendWebRequest();
+                Texture2D texture = (request.downloadHandler as DownloadHandlerTexture).texture;
+                poemPhotoData.Ntexture = new NTexture(texture);
             }
-            catch (WebException ex)
-            {
-                ET.Log.Debug("zoyaeee");
-
-                //  webResponse = ex.Response as HttpWebResponse;
-                ET.Log.Debug(ex.Response.ToString());
-                return null;
-            }
-
+            // try
+            // {
+
+            //     HttpWebRequest webRequest = HttpWebRequest.Create(poemPhotoData.PictureTempUrl) as HttpWebRequest;
+            //     webRequest.Method = "GET";
+            //     ET.Log.Debug("zoyabbb+Method:" + webRequest.Method);
+
+            //     HttpWebResponse webResponse = webRequest.GetResponse() as HttpWebResponse;
+            //     ET.Log.Debug("zoyabbb" + webResponse);
+
+            //     System.IO.Stream st = webResponse.GetResponseStream();
+            //     ET.Log.Debug("zoyabbb+st:" + st);
+
+            //     byte[] bytes;
+            //     using (var ms = new MemoryStream())
+            //     {
+            //         st.CopyTo(ms);
+            //         bytes = ms.ToArray();
+            //     }
+            //     ET.Log.Debug("zoyaccc");
+
+            //     st.Close();
+            //     webResponse.Close();
+            //     webRequest.Abort();
+            //     ET.Log.Debug("zoyaddd");
+            //     poemPhotoData.Bytes = bytes;
+            // }
+            // catch (WebException ex)
+            // {
+            //     ET.Log.Debug("zoyaeee");
+
+            //     //  webResponse = ex.Response as HttpWebResponse;
+            //     ET.Log.Debug(ex.Response.ToString());
+            // }
 
         }
-
         //批量删除玩家相册
         public static async ETTask<bool> ReqRemovedPhoto(List<long> pictureIds, int sourceType)
         {

+ 17 - 2
GameClient/Assets/Game/HotUpdate/Views/DressUp/PhotographSaveView.cs

@@ -1,5 +1,6 @@
 using System;
 using System.Collections;
+using System.Collections.Generic;
 using System.IO;
 using ET;
 using FairyGUI;
@@ -11,6 +12,7 @@ namespace GFGGame
     public class PhotographSaveView : BaseView
     {
         private UI_PhotographSaveUI _ui;
+        private Texture2D tex;
         private byte[] bytes;
 
         protected override void OnInit()
@@ -29,7 +31,7 @@ namespace GFGGame
         protected override void OnShown()
         {
             base.OnShown();
-            Texture2D tex = this.viewData as Texture2D;
+            tex = this.viewData as Texture2D;
             bytes = tex.EncodeToJPG();//将纹理数据,转化成一个jpg图片
             _ui.m_imgRes.texture = new NTexture(tex);
             float width = _ui.m_imgBorder.width;
@@ -80,9 +82,22 @@ namespace GFGGame
             string code = PoemPhotoSProxy.PushToHWCloud(rsp[0], bytes);
             if (string.IsNullOrEmpty(code)) return;
 
-            PoemPhotoSProxy.ReqAddTophoto(rsp[1], (int)PictureSourceType.PersonalAlbum).Coroutine();
+            long result = await PoemPhotoSProxy.ReqAddTophoto(rsp[1], (int)PictureSourceType.PersonalAlbum);
 
+            if (result > 0)
+            {
+                List<PoemPhotoData> list = PoemPhotoDataManager.Instance.PersonalPhotoInfos;
+
+                for (int i = 0; i < list.Count; i++)
+                {
+                    if (list[i].PictureId == result)
+                    {
+                        list[i].Ntexture = new NTexture(tex);
 
+                        break;
+                    }
+                }
+            }
         }
     }
 }