Browse Source

增加排行榜头像显示

大爷 1 year ago
parent
commit
1dd8523de2

BIN
Unity/Assets/Res/FGUI/HUD_atlas0.png


BIN
Unity/Assets/Res/FGUI/HUD_atlas0_1.png


BIN
Unity/Assets/Res/FGUI/HUD_fui.bytes


BIN
Unity/Assets/Res/FGUI/HeadBar_fui.bytes


BIN
Unity/Assets/Res/FGUI/paiming_atlas0.png


BIN
Unity/Assets/Res/FGUI/paiming_fui.bytes


+ 20 - 0
Unity/Assets/Scripts/Codes/HotfixView/Client/Battle/GameoverHanler.cs

@@ -84,11 +84,31 @@ namespace ET
                 }
                 chd.GetChild("name").text = data[i].Name;
                 chd.GetChild("score").text = data[i].Value.ToString();
+
+                var mask = chd.GetChild("icon").asCom;
+                var icon = mask.GetChild("iconLoader").asLoader;
+                var url = data[i].Url;
+                if (!string.IsNullOrEmpty(url))
+                {
+                    LoadHeadIcon(icon, url).Coroutine();
+                }
             }
             for (; i < list.numChildren; i++)
             {
                 list.GetChildAt(i).visible = false;
             }
         }
+
+        private async ETTask LoadHeadIcon(GLoader loader, string url)
+        {
+            var tex = await UrlImageLoader.Instance.LoadImage(url);
+            if (tex != null)
+            {
+                if (GRoot.inst.GetChild("paiming") != null)
+                {
+                    loader.texture = new NTexture(tex);
+                }
+            }
+        }
     }
 }

+ 1 - 0
Unity/Assets/Scripts/Codes/HotfixView/Client/EntryEvent3_InitClient.cs

@@ -11,6 +11,7 @@ namespace ET.Client
             Game.AddSingleton<GlobalViewMgr>();
             Game.AddSingleton<EffectMgr>();
             Game.AddSingleton<SoundManager>();
+            Game.AddSingleton<UrlImageLoader>();
 
             await SceneFactory.CreateClientScene( 1, "Game" );
             await EventSystem.Instance.PublishWait<ShowLoginUIEvent>();

+ 33 - 18
Unity/Assets/Scripts/Codes/HotfixView/Client/UI/HUD/CreateHUD.cs

@@ -38,6 +38,7 @@ namespace ET.Client
                 HUDComonent.listGift[i - 1] = view.GetChild($"CompGift{i}").asCom;
             }
 
+            HUDComonent.listRank.visible = false;
             HUDComonent.pgTower.visible = false;
             HUDComonent.pgBoss1.visible = false;
             HUDComonent.pgBoss2.visible = false;
@@ -147,33 +148,47 @@ namespace ET.Client
             var list = HUDComonent.listRank;
             if (list == null) return;
 
-            list.visible = a.InfoList != null && a.InfoList.Count > 0;
-            if(list.visible)
+            for (int i = 0; i < a.InfoList.Count && i < list.numChildren; i++)
             {
-                int i = 0;
-                for (; i < a.InfoList.Count; i++)
+                var chd = list.GetChildAt(i).asCom;
+                if(chd == null)
                 {
-                    var chd = list.GetChildAt(i).asCom;
-                    if(chd == null)
-                    {
-                        return;
-                    }
-                    var txt = chd.GetChild("text");
-                    txt.text = a.InfoList[i].Name;
-                    chd.visible = true;
+                    return;
                 }
-                for(; i < 3; i++)
+                var txt = chd.GetChild("text");
+                txt.text = a.InfoList[i].Name;
+                var mask = chd.GetChild("compIcon").asCom;
+                var icon = mask.GetChild("iconLoader").asLoader;
+                var url = a.InfoList[i].Url;
+                if (!string.IsNullOrEmpty(url))
                 {
-                    var chd = list.GetChildAt(i);
-                    if(chd != null)
-                    {
-                        chd.visible = false;
-                    }
+                    LoadHeadIcon(icon, url).Coroutine();
+                }
+                chd.visible = true;
+            }
+            for(int i = a.InfoList.Count; i < list.numChildren; i++)
+            {
+                var chd = list.GetChildAt(i);
+                if(chd != null)
+                {
+                    chd.visible = false;
                 }
             }
 
             await ETTask.CompletedTask;
         }
+
+        private async ETTask LoadHeadIcon(GLoader loader, string url)
+        {
+            var tex = await UrlImageLoader.Instance.LoadImage(url);
+            if (tex != null)
+            {
+                if (GRoot.inst.GetChild("HUD") != null)
+                {
+                    loader.texture = new NTexture(tex);
+                }
+            }
+        }
     }
     [Event]
     public class ShowUIAnimationHandler : BEvent<ShowUIAnimation>

+ 8 - 0
Unity/Assets/Scripts/Codes/Model/Client/Helper.meta

@@ -0,0 +1,8 @@
+fileFormatVersion: 2
+guid: ae729a9b46646c04db8ad4a529ad508f
+folderAsset: yes
+DefaultImporter:
+  externalObjects: {}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 56 - 0
Unity/Assets/Scripts/Codes/Model/Client/Helper/UrlImageLoader.cs

@@ -0,0 +1,56 @@
+using System;
+using System.Drawing;
+using System.Drawing.Imaging;
+using System.IO;
+using System.Net;
+using System.Threading.Tasks;
+using UnityEngine;
+
+namespace ET
+{
+    public class UrlImageLoader: Singleton<UrlImageLoader>//, ISingletonAwake
+    {
+        const string ImgPrefix = "omm_di_";
+
+        private int FileIndex = 0;
+        private string TmpImgFile(String url)
+        {
+            string ext = ".png";
+            if (url.EndsWith(".jpg") || url.EndsWith(".png") || url.EndsWith(".gif"))
+            {
+                ext = url.Substring(url.Length - 4);
+            }
+            var file = ImgPrefix + (++FileIndex) + ext;
+            return Path.Combine(Application.persistentDataPath, file);
+        }
+
+
+        public async Task<Texture2D> LoadImage(string url)
+        {
+            try
+            {
+                var imgFile = TmpImgFile(url);
+                await new WebClient().DownloadFileTaskAsync(url, imgFile);
+
+                var stream = new FileStream(imgFile, FileMode.Open, FileAccess.Read);
+                Image img = Image.FromStream(stream);
+                Texture2D tex = new Texture2D(img.Width, img.Height);
+                img.Dispose();
+
+                stream.Seek(0, SeekOrigin.Begin);
+                var bytes = new Byte[stream.Length];
+                stream.Read(bytes, 0, bytes.Length);
+                ImageConversion.LoadImage(tex, bytes, false);
+
+                stream.Close();
+                return tex;
+            }
+            catch(Exception e) 
+            {
+                Log.Error($"Load error: url\n" + e);
+            }
+
+            return null;  
+        }
+    }
+}

+ 11 - 0
Unity/Assets/Scripts/Codes/Model/Client/Helper/UrlImageLoader.cs.meta

@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: 0e0a8cad84940434a8dfdbac6ca2ea61
+MonoImporter:
+  externalObjects: {}
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: