Browse Source

搭配赛排行榜优化???

hexiaojie 11 months ago
parent
commit
21da37f416

+ 5 - 1
GameClient/Assets/Game/HotUpdate/Data/MatchingCompetitionDataManager.cs

@@ -70,7 +70,11 @@ namespace GFGGame
         public NTexture MyNtextture;
         public byte[] MyBytes;
         //本期排行榜数据
-        public List<MatchingPhotoWorksData> _currentRankList = new List<MatchingPhotoWorksData>();
+        public List<CurRanMatchingPhotoWorksData> _currentRankList = new List<CurRanMatchingPhotoWorksData>();
+        //本期排行榜数据--协程锁变量
+        public bool IsWork = false;
+        //本期排行榜数据--协程消息队列
+        public Queue<int> _coroutineQueue = new Queue<int>();
         //往期作品集
         public List<MatchingWorksData> _BeforeWorksList = new List<MatchingWorksData>();
         //往期排行榜数据

+ 44 - 2
GameClient/Assets/Game/HotUpdate/Data/MatchingPhotoHelper.cs

@@ -33,10 +33,23 @@ namespace GFGGame
             {
                 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++)
@@ -46,6 +59,7 @@ namespace GFGGame
                 int count = 0;
                 yield return DownloadPicture(data, count);
             }
+            
             ET.Log.Debug("Download  finish!!!");
             EventAgent.DispatchEvent(ConstMessage.DOWNLOAD_FINISH);
         }
@@ -68,6 +82,34 @@ namespace GFGGame
             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)
         {

+ 19 - 0
GameClient/Assets/Game/HotUpdate/Data/VO/MatchingCompetitionData.cs

@@ -41,6 +41,25 @@ namespace GFGGame
         public float rotationZ = 0f;
         public Vector3 scale = new Vector3(1,1,1);
     }
+    
+    //搭配赛当期排行榜作品信息
+    public class CurRanMatchingPhotoWorksData
+    {
+        public long RoleId { get; set; }
+
+        public bool IsUp = true;
+
+        public JudgingRoundRoleInfo JudgingInfo;
+        /// <summary>
+        /// 照片数据
+        /// </summary>
+        public byte[] Bytes;
+        /// <summary>
+        /// 照片资源
+        /// </summary>
+        public NTexture Ntexture;//个人相册数据
+    }
+    
     //搭配赛作品信息
     public class MatchingPhotoWorksData
     {

+ 30 - 7
GameClient/Assets/Game/HotUpdate/ServerProxy/MatchingCompetitionSproxy.cs

@@ -1,4 +1,6 @@
-using ET;
+using System;
+using System.Collections;
+using ET;
 using GFGGame;
 using FairyGUI;
 using UnityEngine;
@@ -58,6 +60,7 @@ namespace GFGGame
         //    if (!(response is { Error: ErrorCode.ERR_Success })) return false;
         //    return true;
         //}
+        
         //获取一个热门推荐的玩家
         public static async ETTask<bool> ReqGetOnePlayers()
         {
@@ -155,6 +158,7 @@ namespace GFGGame
         //获取当前排行榜
         public static async ETTask<bool> ReqCurrentRank(bool isPushEvent = false)
         {
+            MatchingCompetitionDataManager.Instance.IsWork = true;
             var response =
                 (S2C_GetCurJudgingRoundRankList)await MessageHelper.SendToServer(new C2S_GetCurJudgingRoundRankList
                     { });
@@ -187,12 +191,12 @@ namespace GFGGame
             
             foreach (var judgingRoundRoleInfo in response.JudgingRoundRoleInfoList)
             {
-                MatchingPhotoWorksData matchingPhotoWorksData =
+                CurRanMatchingPhotoWorksData matchingPhotoWorksData =
                     MatchingCompetitionDataManager.Instance._currentRankList.FirstOrDefault(a =>
                         a.RoleId == judgingRoundRoleInfo.RoleId);
                 if (matchingPhotoWorksData == null)
                 {
-                    matchingPhotoWorksData = new MatchingPhotoWorksData
+                    matchingPhotoWorksData = new CurRanMatchingPhotoWorksData
                     {
                         RoleId = judgingRoundRoleInfo.RoleId,
                         JudgingInfo = judgingRoundRoleInfo
@@ -239,9 +243,9 @@ namespace GFGGame
                 }
             });
             
-            Timers.inst.StartCoroutine(
-                MatchingPhotoHelper.Download(MatchingCompetitionDataManager.Instance._currentRankList));
-
+            var enumerator = MatchingPhotoHelper.DownloadExt(MatchingCompetitionDataManager.Instance._currentRankList);
+            Timers.inst.StartCoroutine(enumerator);
+            
             //推送事件
             if (isPushEvent)
             {
@@ -250,6 +254,25 @@ namespace GFGGame
 
             return true;
         }
+        
+        public static void UseCoroutine()
+        {
+            if (!MatchingCompetitionDataManager.Instance.IsWork)
+            {
+                if (MatchingCompetitionDataManager.Instance._coroutineQueue.Count == 0)
+                {
+                    return;
+                }
+                
+                int vl = MatchingCompetitionDataManager.Instance._coroutineQueue.Dequeue();
+                if (vl == 1)
+                {
+                    //缓存里面存在数据,那也要再次请求服务器进行更新数据,只是用协程的形式,接着处理完数据后抛出事件
+                    ReqCurrentRank(true).Coroutine();
+                }
+            }
+        }
+        
         //获取往期作品集
         public static async ETTask<bool> ReqBeforeWorks()
         {
@@ -268,7 +291,7 @@ namespace GFGGame
         //获取往期作品排行榜
         public static async ETTask<bool> ReqBeforeRank(int id)
         {
-            var response = (S2C_GetOldJudgingRoundRankList)await MessageHelper.SendToServer(new C2S_GetOldJudgingRoundRankList { JudgingRoundOpenId = id});
+             var response = (S2C_GetOldJudgingRoundRankList)await MessageHelper.SendToServer(new C2S_GetOldJudgingRoundRankList { JudgingRoundOpenId = id});
             if (!(response is { Error: ErrorCode.ERR_Success })) return false;
             MatchingCompetitionDataManager.Instance._BeforeRankList.Clear();
             foreach (var item in response.JudgingRoundRoleInfoList)

+ 12 - 4
GameClient/Assets/Game/HotUpdate/Views/MatchingCompetition/MatchingCompetitionRankView.cs

@@ -55,14 +55,22 @@ namespace GFGGame
             base.AddEventListener();
             EventAgent.AddEventListener(ConstMessage.DOWNLOAD_FINISH, UpdateView);
             EventAgent.AddEventListener(ConstMessage.REQ_CURRENT_RANK, UpdateView);
+            EventAgent.AddEventListener(ConstMessage.DOWNLOAD_FINISH, ViewUseCoroutine);
         }
         protected override void RemoveEventListener()
         {
             base.RemoveEventListener();
             EventAgent.RemoveEventListener(ConstMessage.DOWNLOAD_FINISH, UpdateView);
             EventAgent.RemoveEventListener(ConstMessage.REQ_CURRENT_RANK, UpdateView);
+            EventAgent.RemoveEventListener(ConstMessage.DOWNLOAD_FINISH, ViewUseCoroutine);
         }
-     private void UpdateView()
+
+        private void ViewUseCoroutine()
+        {
+            MatchingCompetitionSproxy.UseCoroutine();
+        }
+
+        private void UpdateView()
         {
             //排序
             MatchingCompetitionDataManager.Instance._currentRankList.Sort((a, b) =>
@@ -84,7 +92,7 @@ namespace GFGGame
             
             if(MatchingCompetitionDataManager.Instance._currentRankList.Count > 0)
             {
-                MatchingPhotoWorksData otherInfo = MatchingCompetitionDataManager.Instance._currentRankList[0];
+                CurRanMatchingPhotoWorksData otherInfo = MatchingCompetitionDataManager.Instance._currentRankList[0];
                 _ui.m_playerImage.texture = otherInfo.Ntexture;
             }
             else
@@ -104,7 +112,7 @@ namespace GFGGame
         private void RenderRankList(int index, GObject obj)
         {
             UI_Component3 item = UI_Component3.Proxy(obj);
-            MatchingPhotoWorksData otherdata = MatchingCompetitionDataManager.Instance._currentRankList[index];
+            CurRanMatchingPhotoWorksData otherdata = MatchingCompetitionDataManager.Instance._currentRankList[index];
             JudgingRoundRoleInfo otherInfo = otherdata.JudgingInfo;
             otherInfo.Rank = index + 1;
             RoleInfoManager.Instance.UpdateHead(item.m_head, otherInfo.HeadItemId, otherInfo.HeadBorderItemId);
@@ -123,7 +131,7 @@ namespace GFGGame
             GObject item = context.sender as GObject;
             int index = (int)item.data; 
             _currentIndex = index;
-            MatchingPhotoWorksData otherInfo = MatchingCompetitionDataManager.Instance._currentRankList[index];
+            CurRanMatchingPhotoWorksData otherInfo = MatchingCompetitionDataManager.Instance._currentRankList[index];
             _ui.m_playerImage.texture = otherInfo.Ntexture;
         }
         private void OnClickBtnBack()

+ 4 - 2
GameClient/Assets/Game/HotUpdate/Views/MatchingCompetition/MatchingCompetitionUpLoadView.cs

@@ -279,12 +279,14 @@ namespace GFGGame
             }
             else
             {
-                //缓存里面存在数据,那也要再次请求服务器进行更新数据,只是用协程的形式,接着处理完数据后抛出事件
-                MatchingCompetitionSproxy.ReqCurrentRank(true).Coroutine();
+                MatchingCompetitionDataManager.Instance._coroutineQueue.Enqueue(1);
+                MatchingCompetitionSproxy.UseCoroutine();
+                
                 //那就直接显示界面
                 ViewManager.Show<MatchingCompetitionRankView>();
             }
         }
+        
         private async void OnClickBtnExchange()
         {
             if (isCountTime)