Browse Source

增加玩家头顶名字根据玩家人数来决定隐规则:小于20人一直显示:小于30人显示5秒:小于40人显示3秒;小于60人显示1秒;超60人不显示;vip玩家一直显示

大爷 1 year ago
parent
commit
dd306228cf

+ 1 - 1
Unity/Assets/Scripts/Codes/Hotfix/Client/battle/BattleMgr.cs

@@ -129,7 +129,7 @@ namespace ET
             var unit = BattleUnitFactory.Instance.Create(obj);
             if(unit != null )
             {
-                UnitMgr.Instance.PutUnit(obj.ObjectID, unit);
+                UnitMgr.Instance.PutUnit(obj, unit);
                 if (unit is BattleActor)
                 {
                     UnitMgr.Instance.Actor = unit as BattleActor;

+ 13 - 1
Unity/Assets/Scripts/Codes/Hotfix/Client/battle/UnitMgr.cs

@@ -1,5 +1,7 @@
 
+using CommonAI.ZoneClient;
 using CommonLang;
+using System.Collections.Generic;
 
 namespace ET.Client
 {
@@ -18,6 +20,7 @@ namespace ET.Client
         {
             get { return UnitList.Values; }
         }
+        public List<uint> PlayerList = new();
 
         public bool HasUnit(uint unitId)
         {
@@ -27,18 +30,25 @@ namespace ET.Client
         {
             return UnitList.ContainsKey(id) ? UnitList[id] : null;
         }
-        public void PutUnit(uint id, BattleObject obj)
+        public void PutUnit(ZoneObject zo, BattleObject obj)
         {
+            var id = zo.ObjectID;
             if(UnitList.ContainsKey(id))
             {
                 Log.Error($"Already exist unit({id}) @{obj}");
                 UnitList.Remove(id);
             }
             UnitList[id] = obj;
+
+            if(zo is ZoneUnit zu && zu.Force == 1)
+            {
+                 PlayerList.Add(id);
+            }
         }
         public void RemoveUnit(uint id)
         {
             UnitList.Remove(id);
+            PlayerList.Remove(id);
         }
 
         public void RecycleUnits()
@@ -48,11 +58,13 @@ namespace ET.Client
                 kp.Value.OnSleep();
             }
             UnitList.Clear();
+            PlayerList.Clear();
         }
 
         public void Clear()
         {
             UnitList.Clear();
+            PlayerList.Clear();
         }
     }
 }

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

@@ -51,6 +51,7 @@ namespace ET
                     IsGameOver = false;
 
                     UIHelper.RemoveAllUiExceptSth();
+                    GlobalViewMgr.Instance.ReOpenGame();
                     EventSystem.Instance.Publish<ReOpenGame>();
                 });
             });

+ 10 - 4
Unity/Assets/Scripts/Codes/HotfixView/Client/Global/GlobalViewMgr.cs

@@ -4,6 +4,7 @@ using UnityEngine;
 namespace ET.Client
 {
     [ObjectSystem]
+    [FriendOfAttribute(typeof(ET.Client.ModelViewComponent))]
     public class GlobalViewMgr : Singleton<GlobalViewMgr>, ISingletonAwake
     {
         //public Camera UICamera;
@@ -15,11 +16,11 @@ namespace ET.Client
 
         public void Awake()
         {
-            Global = GameObject.Find( "/Global" ).transform;
-            Unit = GameObject.Find( "/Global/Unit" ).transform;
-            RecycleNode = GameObject.Find( "/Global/RecycleNode" ).transform;
+            Global = GameObject.Find("/Global").transform;
+            Unit = GameObject.Find("/Global/Unit").transform;
+            RecycleNode = GameObject.Find("/Global/RecycleNode").transform;
 
-            BattleCamera = GameObject.Find( "/Global/BattleCamera" ).GetComponent<Camera>();
+            BattleCamera = GameObject.Find("/Global/BattleCamera").GetComponent<Camera>();
             CameraMgr.Init();
 
             CreateHeadBar().Coroutine();
@@ -32,5 +33,10 @@ namespace ET.Client
             HeadbarView = root;
             //root.visible = false;
         }
+
+        public void ReOpenGame()
+        {
+            ModelViewComponent.Instance.IsHideNormalName = false;
+        }
     }
 }

+ 71 - 6
Unity/Assets/Scripts/Codes/HotfixView/Client/Unit/OnNewZoneObject.cs

@@ -9,6 +9,7 @@ namespace ET.Client
 {
     [Event]
     [FriendOfAttribute(typeof(ET.Client.UnitRenderComponet))]
+    [FriendOfAttribute(typeof(ET.Client.ModelViewComponent))]
     public class OnNewZoneObjectHandler : BEvent<EventType.OnNewZoneObject>
     {
         protected override async ETTask OnEvent(EventType.OnNewZoneObject args)
@@ -41,7 +42,7 @@ namespace ET.Client
         private async ETTask CreatUnitModel(BattleUnit unit, string modelName)
         {
             var zu = unit.ZUnit;
-            if(modelName.IsNullOrWhitespace() )
+            if (modelName.IsNullOrWhitespace())
             {
                 modelName = $"Unit_{zu.Info.FileName}";
             }
@@ -56,7 +57,7 @@ namespace ET.Client
             var render = ModelViewComponent.Instance.AddChildWithId<UnitRenderComponet, GameObject>(unit.Id, go, true);
             if (zu.Info.Properties is XmdsUnitProperties prop && prop.ShowHPBanner)
             {
-                await CreateHeadbar(render, zu);
+                CreateHeadbar(render, zu).Coroutine();
             }
             if (unit is BattleActor)
             {
@@ -64,7 +65,7 @@ namespace ET.Client
             }
             //Log.Debug($"unitRender({zu.ObjectID}),pos({zu.X},{zu.Y},{zu.Z}) ok.");
 
-            switch(zu.CurrentState)
+            switch (zu.CurrentState)
             {
                 case CommonAI.Zone.Helper.UnitActionStatus.Move:
                     EventSystem.Instance.Publish(PlayAnimatorEvent.Clone(zu.ObjectID, PlayAnimatorEvent.AniType.Run));
@@ -78,7 +79,7 @@ namespace ET.Client
                     EventSystem.Instance.Publish(PlayAnimatorEvent.Clone(zu.ObjectID, PlayAnimatorEvent.AniType.Idle));
                     break;
             }
-            if(zu.GetBuffStatusCount() > 0)
+            if (zu.GetBuffStatusCount() > 0)
             {
                 EventSystem.Instance.Publish(BuffChangeEvent.Static.Clone(zu.ObjectID, null, EventType.BuffChangeEvent.BuffOP.Reload));
             }
@@ -131,12 +132,76 @@ namespace ET.Client
             render.NameBar = name;
             render.HPBar = progresshp;
 
-            name.text = "";
-            name.visible = false;
+            
+            if (zu.Force == 3)
+            {
+                name.text = "";
+                name.visible = false;
+            }
+            else
+            {
+                name.text = zu.SyncInfo.Name;
+                TryShowName(render);
+            }
 
             progresshp.visible = false;
             progresshp.value = zu.HP * 100 / zu.MaxHP;
             render.SyncHeadBarPos();
         }
+
+        private async void TryShowName(UnitRenderComponet render)
+        {
+            if (render.IsVipName)
+            {
+                render.NameBar.visible = true;
+            }
+            else
+            {
+                var unitCnt = UnitMgr.Instance.PlayerList.Count - 7;
+                if (unitCnt <= GameSetting.Name_level_1)
+                {
+                    render.NameBar.visible = true;
+                }
+                else
+                {
+                    if (!ModelViewComponent.Instance.IsHideNormalName)
+                    {
+                        ModelViewComponent.Instance.IsHideNormalName = true;
+                        foreach(var id in UnitMgr.Instance.PlayerList)
+                        {
+                            if (id == render.Id) continue;
+                            var r = ModelViewComponent.Instance.GetChild<UnitRenderComponet>(id);
+                            if (r != null && r.NameBar != null && !r.IsVipName)
+                            {
+                                r.NameBar.visible = false;
+                            }
+                        };
+                    }
+
+                    int showTime;
+                    if (unitCnt < GameSetting.Name_level_2)
+                    {
+                        showTime = 5000;
+                    }
+                    else if(unitCnt < GameSetting.Name_level_3)
+                    {
+                        showTime = 3000;
+                    }
+                    else if(unitCnt < GameSetting.Name_level_4)
+                    {
+                        showTime = 1000;
+                    }
+                    else
+                    {
+                        render.NameBar.visible = false;
+                        return;
+                    }
+
+                    render.NameBar.visible = true;
+                    await TimerComponent.Instance.WaitAsync(showTime);
+                    render.NameBar.visible = false;
+                }
+            }
+        }
     }
 }

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

@@ -80,6 +80,7 @@ namespace ET.Client
             if (unitRender != null)
             {
                 unitRender.NameBar.visible = true;
+                unitRender.IsVipName = true;
             }
             else
             {

+ 4 - 0
Unity/Assets/Scripts/Codes/Model/Client/GameSetting.cs

@@ -5,6 +5,10 @@ namespace ET
     public class GameSetting : Singleton<GameSetting>
     {
         public const bool Cnst_Mute = true;     //静音
+        public const int Name_level_1 = 20;      //少于多少人时,名字一直显示
+        public const int Name_level_2 = 30;      //少于多少人,名字显示5秒
+        public const int Name_level_3 = 40;      //少于多少人时,名字显示3秒
+        public const int Name_level_4 = 60;      //少于多少人时,名字显示1秒
 
         public enum Sets
         {

+ 3 - 0
Unity/Assets/Scripts/Codes/ModelView/Client/Unit/ModelViewComponent.cs

@@ -8,6 +8,9 @@ namespace ET.Client
     {
         [StaticField]
         public static ModelViewComponent Instance;
+
+        //当人数多起来后,是否隐藏了普通用户的名字
+        public bool IsHideNormalName = false;
     }
 
     [FriendOf(typeof(ModelViewComponent))]

+ 3 - 1
Unity/Assets/Scripts/Codes/ModelView/Client/Unit/UnitRenderComponet.cs

@@ -28,10 +28,11 @@ namespace ET.Client
         public GProgressBar HPBar;
         public GObject NameBar;
         public Transform TransHeadInfo;
-
         public Transform TransChest;
         public Transform TransFoot;
 
+        public bool IsVipName;
+
         //TODO: 获得模型绑定部件,如不存在返回Root
         public Transform GetBindPart(string partName)
         {
@@ -100,6 +101,7 @@ namespace ET.Client
             TransFoot = null;
             Commands.Clear();
             BuffEffects.Clear();
+            IsVipName = false;
         }
     }