Parcourir la source

增加同时显示3个BOSS血量条的功能

大爷 il y a 1 an
Parent
commit
ce24230f40

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


+ 62 - 10
Unity/Assets/Scripts/Codes/Hotfix/Client/battle/unit/BattleUnit.cs

@@ -5,6 +5,7 @@ using ET;
 using ET.EventType;
 using Sirenix.Utilities;
 using System;
+using System.Collections.Generic;
 using XmdsCommon.Plugin;
 
 public class BattleUnit : BattleObject
@@ -133,26 +134,77 @@ public class BattleUnit : BattleObject
 
     private void OnHPChanged()
     {
-        var hp = ZUnit.HP;
-        var pg = hp * 100f / ZUnit.MaxHP;
-
         if (ZUnit.Info.Properties is XmdsUnitProperties prop)
         {
             if (prop.GameStatusType == XmdsUnitProperties.StatusType.SpecialElite)
             {
-                EventSystem.Instance.Publish<HPRefresh>(HPRefresh.Static.Clone(HPRefresh.Index.Tower, pg, hp));
-                //Log.Debug($"tower({ZUnit.ObjectID}@{ZUnit.Info.Name}) hp: {ZUnit.HP}/{ZUnit.MaxHP}");
-
+                var hp = ZUnit.HP;
+                var pg = hp * 100f / ZUnit.MaxHP;
+                EventSystem.Instance.Publish(HPRefresh.Clone(HPRefresh.Index.Tower, pg, prop.ServerData.BaseInfo.name, hp.ToString()));
+                return;
             }
             else if (prop.GameStatusType == XmdsUnitProperties.StatusType.SpecialBoss)
             {
-                EventSystem.Instance.Publish<HPRefresh>(HPRefresh.Static.Clone(HPRefresh.Index.Boss, pg, hp));
-                //Log.Debug($"Boss({ZUnit.ObjectID}) hp: {ZUnit.HP}/{ZUnit.MaxHP}");
+                RefreshBossHPBar(prop);
+                return;
+            }
+            //Log.Debug($"hp({ZUnit.ObjectID}) change: {ZUnit.HP}");
+
+            if (prop.ShowHPBanner)
+            {
+                EventSystem.Instance.Publish(SyncUnitHpEvent.Clone(Id, ZUnit.HP * 100f / ZUnit.MaxHP));
+            }
+        }
+    }
+
+    //有3个HP血条,找合适的条条显示
+    private static List<ZoneUnit> pgList = new();
+    private void RefreshBossHPBar(XmdsUnitProperties prop)
+    {
+        var hp = ZUnit.HP;
+        int hide = -1;
+        for(var i = 0; i < pgList.Count; i++)
+        {
+            var unit = pgList[i];
+            if(hide >= 0)
+            {
+                hp = unit.HP;
+                prop = unit.Info.Properties as XmdsUnitProperties;
+                EventSystem.Instance.Publish(HPRefresh.Clone(HPRefresh.Index.Boss1 + i - 1, hp * 100f / unit.MaxHP, prop.ServerData.BaseInfo.name, hp.ToString()));
+            }
+            else if(unit.TemplateID == ZUnit.TemplateID)
+            {
+                if(hp <= 0)
+                {
+                    hide = i;
+                    EventSystem.Instance.Publish(HPRefresh.Clone(HPRefresh.Index.Boss1 + pgList.Count - 1, 0, "", "", false));
+                }
+                else
+                {
+                    EventSystem.Instance.Publish(HPRefresh.Clone(HPRefresh.Index.Boss1 + i, hp * 100f / ZUnit.MaxHP, prop.ServerData.BaseInfo.name, hp.ToString()));
+                    return;
+                }
             }
         }
-        //Log.Debug($"hp({ZUnit.ObjectID}) change: {ZUnit.HP}");
+        if(hide >= 0)
+        {
+            pgList.RemoveAt(hide);
+            return;
+        }
+
+        if (pgList.Count >= 3)
+        {
+            Log.Error("wtf, more than 3 boss.");
+            return;
+        }
+
+        if(hp <= 0)
+        {
+            return;
+        }
 
-        EventSystem.Instance.Publish(SyncUnitHpEvent.Clone(Id, pg));
+        pgList.Add(ZUnit);
+        EventSystem.Instance.Publish(HPRefresh.Clone(HPRefresh.Index.Boss1 + pgList.Count-1, hp * 100f / ZUnit.MaxHP, prop.ServerData.BaseInfo.name, hp.ToString()));
     }
 
     protected virtual void OnActionChanged(ZoneUnit unit, UnitActionStatus status, object evt)

+ 71 - 31
Unity/Assets/Scripts/Codes/HotfixView/Client/UI/HUD/CreateHUD.cs

@@ -10,25 +10,35 @@ namespace ET.Client
         {
             var view = await UIHelper.Create( "HUD" );
 
-            var progress1 = view.GetChild("HPBar1") as GProgressBar;
-            var progress2 = view.GetChild("HPBar2") as GProgressBar;
-            progress1.visible = progress2.visible = false;
-            var txthp1 = progress1.GetChild("title");
-            txthp1.text = "";
-            var txthp2 = progress2.GetChild("title");
-            txthp2.text = "";
+            var pgTower = view.GetChild("HPBarTower") as GProgressBar;
+            var pgBoss1 = view.GetChild("HPBarBoss1") as GProgressBar;
+            var pgBoss2 = view.GetChild("HPBarBoss2") as GProgressBar;
+            var pgBoss3 = view.GetChild("HPBarBoss3") as GProgressBar;
+            var progresslike = view.GetChild("EnergyBar") as GProgressBar;
 
+            pgTower.visible = false;
+            pgBoss1.visible = false;
+            pgBoss2.visible = false;
+            pgBoss3.visible = false;
+            progresslike.visible = false;
+
+            var compIcon = view.GetChild("Comp_gifticon");
+            var compTips = view.GetChild("Comp_tips");
             var btn = view.GetChild("btn_start");
             btn.onClick.Set(() =>
             {
                 btn.visible = false;
+                compIcon.visible = false;
+                compTips.visible = false;
 
                 CameraMgr.PlayStartAnimation(() =>
                 {
+                    compIcon.visible = true;
                     EventSystem.Instance.Publish(BattleFunc.Clone((int)BattleFunc.FUNC.Start));
                 }).Coroutine();
-                
             });
+
+            EventSystem.Instance.Publish(BattleFunc.Clone((int)BattleFunc.FUNC.ClientIsReady));
         }
     }
 
@@ -50,10 +60,11 @@ namespace ET.Client
     [Event]
     public class HPRefreshEventHandler : BEvent<HPRefresh>
     {
-        GProgressBar progressBar1;
-        GProgressBar progressBar2;
-        GTextField txt1;
-        GTextField txt2;
+        GProgressBar pgTower;
+        GProgressBar pgBoss1;
+        GProgressBar pgBoss2;
+        GProgressBar pgBoss3;
+        GProgressBar pgTKLike;
 
         protected override async ETTask OnEvent(HPRefresh a)
         {
@@ -61,31 +72,60 @@ namespace ET.Client
             if (view != null)
             {
                 GProgressBar progress = null;
-                GTextField txt = null;
-                if (a.HPIndex == HPRefresh.Index.Tower)
+                switch (a.HPIndex)
                 {
-                    if (progressBar1 == null)
-                    {
-                        progressBar1 = view.GetChild("HPBar1").asProgress;
-                        txt1 = progressBar1.GetChild("title").asTextField;
-                    }
-                    progress = progressBar1;
-                    txt = txt1;
+                    case HPRefresh.Index.Tower:
+                        if (pgTower == null)
+                        {
+                            pgTower = view.GetChild("HPBarTower").asProgress;
+                        }
+                        progress = pgTower;
+                        break;
+                    case HPRefresh.Index.Boss1:
+                        if (pgBoss1 == null)
+                        {
+                            pgBoss1 = view.GetChild("HPBarBoss1").asProgress;
+                        }
+                        progress = pgBoss1;
+                        break;
+                    case HPRefresh.Index.Boss2:
+                        if (pgBoss2 == null)
+                        {
+                            pgBoss2 = view.GetChild("HPBarBoss2").asProgress;
+                        }
+                        progress = pgBoss2;
+                        break;
+                    case HPRefresh.Index.Boss3:
+                        if (pgBoss3 == null)
+                        {
+                            pgBoss3 = view.GetChild("HPBarBoss3").asProgress;
+                        }
+                        progress = pgBoss3;
+                        break;
+                    case HPRefresh.Index.TiktokLike:
+                        if (pgTKLike == null)
+                        {
+                            pgTKLike = view.GetChild("EnergyBar").asProgress;
+                        }
+                        progress = pgTKLike;
+                        break;
                 }
-                else
+                
+                progress.visible = a.Visible;
+                if (a.Visible)
                 {
-                    if (progressBar2 == null)
+                    progress.value = a.Progress;
+                    var name = progress.GetChild("name");
+                    if (name != null)
+                    {
+                        name.text = a.Name;
+                    }
+                    var txt = progress.GetChild("title");
+                    if (txt != null)
                     {
-                        progressBar2 = view.GetChild("HPBar2").asProgress;
-                        txt2 = progressBar2.GetChild("title").asTextField;
+                        txt.text = a.Title;
                     }
-                    progress = progressBar2;
-                    txt = txt2;
                 }
-
-                progress.visible = true;
-                progress.value = a.Progress;
-                txt.text = a.Progress.ToString("F2") + "%";
             }
             await ETTask.CompletedTask;
         }

+ 16 - 7
Unity/Assets/Scripts/Codes/Model/Client/EventTypeClient.cs

@@ -179,6 +179,7 @@ namespace ET
                 Start = 1001,
                 Start2,
                 Start3,
+                ClientIsReady,
             }
             public int FuncIndex;
             public static BattleFunc Static = new();
@@ -192,18 +193,26 @@ namespace ET
         {
             public enum Index
             {
-                Tower = 1, Boss
+                Tower = 1,
+                Boss1,
+                Boss2,
+                Boss3,
+                TiktokLike
             }
             public Index HPIndex;
             public float Progress;
-            public int HP;
+            public string Name;
+            public string Title;
+            public bool Visible;
             public static HPRefresh Static = new();
-            public HPRefresh Clone(Index i, float pg, int hp)
+            public static HPRefresh Clone(Index i, float progress, string name="", string title="", bool visible = true)
             {
-                HPIndex = i;
-                Progress = pg;
-                HP = hp;
-                return this;
+                Static.HPIndex = i;
+                Static.Progress = progress;
+                Static.Name = name;
+                Static.Title = title;
+                Static.Visible = visible;
+                return Static;
             }
         }
         public class CameraEvent