Quellcode durchsuchen

搭配赛图片优化补充提交

zhangyuqian vor 1 Jahr
Ursprung
Commit
0cbf9ae07d

+ 24 - 4
GameClient/Assets/Game/HotUpdate/Data/MatchingCompetitionDataManager.cs

@@ -71,6 +71,8 @@ namespace GFGGame
         public byte[] MyBytes;
         //本期排行榜数据
         public List<MatchingPhotoWorksData> _currentRankList = new List<MatchingPhotoWorksData>();
+        //本期排行榜图片数据
+        public Dictionary<string, NTexture> _currentImageDic = new Dictionary<string, NTexture>();
         //往期作品集
         public List<MatchingWorksData> _BeforeWorksList = new List<MatchingWorksData>();
         //往期排行榜数据
@@ -639,6 +641,10 @@ namespace GFGGame
             {
                 // 目录已存在
             }
+            if(targerPath == LocalBeforePath)
+            {
+                return;
+            }
             //判断手机内是否存在该图片
             string path = Path.Combine(targerPath, string.Format("/{0}.jpg", ImageName.ToString()));
             bool fileExists = File.Exists(path);
@@ -684,10 +690,24 @@ namespace GFGGame
         public NTexture GetTargetImage(string ImageName,string Path)
         {
             string AllPath = Path +"/"+ ImageName;
-            byte[] fileData = File.ReadAllBytes(AllPath);
-            Texture2D texture = new Texture2D(1, 1);
-            texture.LoadImage(fileData);
-            return new NTexture(texture);
+            //byte[] fileData = File.ReadAllBytes(AllPath);
+            byte[] fileData;
+            Texture2D texture = new Texture2D(512,512);
+            //texture.LoadImage(fileData);
+            //return new NTexture(texture);
+            using (FileStream fileStream = new FileStream(AllPath, FileMode.Open, FileAccess.Read))
+            {
+                fileData = new byte[fileStream.Length];
+                int bytesRead = fileStream.Read(fileData, 0, fileData.Length);
+                if (bytesRead != fileData.Length)
+                {
+                    Debug.LogError("未能完全读取文件");
+                    return null;
+                }
+                texture.LoadImage(fileData);
+                fileStream.Close();
+                return new NTexture(texture);
+            }
         }
         //删除指定图片
         public void DeleteImage(string imagePath)

+ 13 - 4
GameClient/Assets/Game/HotUpdate/Data/MatchingPhotoHelper.cs

@@ -39,9 +39,9 @@ namespace GFGGame
 
         public static IEnumerator Download(List<MatchingPhotoWorksData> list,string targetPath)
         {
+            List<string> imageList = MatchingCompetitionDataManager.Instance.GetImageFileNames(targetPath);
             for (int i = 0; i < list.Count; i++)
-            {
-                List<string> imageList = MatchingCompetitionDataManager.Instance.GetImageFileNames(targetPath);
+            {  
                 string ImageName = list[i].JudgingInfo.WorksId.ToString() + ".jpg";
                 //排行榜内图片是否存在本地,否就下载,是就赋值
                 if (!MatchingCompetitionDataManager.Instance.RankIdisInLocal(ImageName, imageList))
@@ -53,8 +53,13 @@ namespace GFGGame
                 }
                 else
                 {
-                    list[i].Bytes = File.ReadAllBytes((targetPath+ "/" + ImageName));
-                    list[i].Ntexture = MatchingCompetitionDataManager.Instance.GetTargetImage(ImageName,targetPath);
+                    //这个变量没用处
+                    //list[i].Bytes = File.ReadAllBytes((targetPath+ "/" + ImageName));
+                    if(!MatchingCompetitionDataManager.Instance._currentImageDic.ContainsKey(list[i].JudgingInfo.WorksId.ToString()))
+                    {
+                        MatchingCompetitionDataManager.Instance._currentImageDic.Add(list[i].JudgingInfo.WorksId.ToString(), MatchingCompetitionDataManager.Instance.GetTargetImage(ImageName, targetPath));
+                    }
+                    //list[i].Ntexture = MatchingCompetitionDataManager.Instance.GetTargetImage(ImageName,targetPath);
                     yield return null;
                 }
                 //本地图片是否存在排行榜,否就删除
@@ -114,6 +119,10 @@ namespace GFGGame
                     Texture2D texture = (request.downloadHandler as DownloadHandlerTexture).texture;
                     data.Ntexture = new NTexture(texture);
                     data.Bytes = texture.EncodeToJPG();
+                    if (!MatchingCompetitionDataManager.Instance._currentImageDic.ContainsKey(data.JudgingInfo.WorksId.ToString()))
+                    {
+                        MatchingCompetitionDataManager.Instance._currentImageDic.Add(data.JudgingInfo.WorksId.ToString(), data.Ntexture);
+                    }
                     MatchingCompetitionDataManager.Instance.DownloadImageToLocal(data.Bytes,data.JudgingInfo.WorksId,targetPath);
                 }
             }

+ 14 - 1
GameClient/Assets/Game/HotUpdate/ServerProxy/MatchingCompetitionSproxy.cs

@@ -47,6 +47,10 @@ namespace GFGGame
             {
                 Timers.inst.StartCoroutine(MatchingPhotoHelper.DownloadMyself(response.MyWorks.PictureTempUrl,MatchingCompetitionDataManager.Instance.LoaclMy));
             }
+            if(MatchingCompetitionDataManager.Instance.MatchingState !=1)
+            {
+                //MatchingCompetitionSproxy.ReqCurrentRank().Coroutine();
+            }
             MatchingCompetitionDataManager.Instance.AnalysisInfoToList();
             return true;
         }
@@ -157,11 +161,20 @@ namespace GFGGame
             var response = (S2C_GetCurJudgingRoundRankList)await MessageHelper.SendToServer(new C2S_GetCurJudgingRoundRankList { });
             if (!(response is { Error: ErrorCode.ERR_Success })) return false;
             MatchingCompetitionDataManager.Instance._currentRankList.Clear();
+            int i = 0;
             foreach (var item in response.JudgingRoundRoleInfoList)
             {
                 MatchingPhotoWorksData data = new MatchingPhotoWorksData();
                 data.JudgingInfo = item;
-                MatchingCompetitionDataManager.Instance._currentRankList.Add(data);
+                if (i >= MatchingCompetitionDataManager.Instance._currentRankList.Count)
+                {
+                    MatchingCompetitionDataManager.Instance._currentRankList.Add(data);
+                }
+                else
+                {
+                    MatchingCompetitionDataManager.Instance._currentRankList[i] = data;
+                }
+                i++;
             }
             Timers.inst.StartCoroutine(MatchingPhotoHelper.Download(MatchingCompetitionDataManager.Instance._currentRankList,MatchingCompetitionDataManager.Instance.LocalRankPath));
             return true;

+ 20 - 3
GameClient/Assets/Game/HotUpdate/Views/MatchingCompetition/MatchingCompetitionRankView.cs

@@ -63,8 +63,17 @@ namespace GFGGame
         {
             if(MatchingCompetitionDataManager.Instance._currentRankList.Count > 0)
             {
-                MatchingPhotoWorksData otherInfo = MatchingCompetitionDataManager.Instance._currentRankList[0];
-                _ui.m_playerImage.texture = otherInfo.Ntexture;
+                //MatchingPhotoWorksData otherInfo = MatchingCompetitionDataManager.Instance._currentRankList[0];
+                //_ui.m_playerImage.texture = otherInfo.Ntexture;
+                MatchingPhotoWorksData otherInfo = MatchingCompetitionDataManager.Instance._currentRankList[index];
+                if (MatchingCompetitionDataManager.Instance._currentImageDic.ContainsKey(otherInfo.JudgingInfo.WorksId.ToString()))
+                {
+                    _ui.m_playerImage.texture = MatchingCompetitionDataManager.Instance._currentImageDic[otherInfo.JudgingInfo.WorksId.ToString()];
+                }
+                else
+                {
+                    _ui.m_playerImage.texture = null;
+                }
             }
             else
             {
@@ -103,7 +112,15 @@ namespace GFGGame
             int index = (int)item.data; 
             _currentIndex = index;
             MatchingPhotoWorksData otherInfo = MatchingCompetitionDataManager.Instance._currentRankList[index];
-            _ui.m_playerImage.texture = otherInfo.Ntexture;
+            if(MatchingCompetitionDataManager.Instance._currentImageDic.ContainsKey(otherInfo.JudgingInfo.WorksId.ToString()))
+            {
+                _ui.m_playerImage.texture = MatchingCompetitionDataManager.Instance._currentImageDic[otherInfo.JudgingInfo.WorksId.ToString()];
+            }
+            else
+            {
+                _ui.m_playerImage.texture = null;
+            }
+            //_ui.m_playerImage.texture = otherInfo.Ntexture;
         }
         private void OnClickBtnBack()
         {

+ 9 - 1
GameClient/Assets/Game/HotUpdate/Views/MatchingCompetition/MatchingCompetitionWorkListView.cs

@@ -78,7 +78,15 @@ namespace GFGGame
             RoleInfoManager.Instance.UpdateHead(item.m_head, otherInfo.HeadItemId, otherInfo.HeadBorderItemId);
             item.m_nameText.text = otherInfo.RoleName.ToString();
             item.m_countText.text = otherInfo.Score.ToString();
-            item.m_playerImage.texture = otherdata.Ntexture;
+            //item.m_playerImage.texture = otherdata.Ntexture;          
+            if (MatchingCompetitionDataManager.Instance._currentImageDic.ContainsKey(otherInfo.WorksId.ToString()))
+            {
+                item.m_playerImage.texture = MatchingCompetitionDataManager.Instance._currentImageDic[otherInfo.WorksId.ToString()];
+            }
+            else
+            {
+                item.m_playerImage.texture = null;
+            }
             item.m_descText.text = (index+1).ToString();
             if (item.target.data == null)
             {