diff --git a/client/Assets/Game/Scripts/UI/Sub/PageHeadbar.cs b/client/Assets/Game/Scripts/UI/Sub/PageHeadbar.cs index fb49eb2..a76cdbd 100644 --- a/client/Assets/Game/Scripts/UI/Sub/PageHeadbar.cs +++ b/client/Assets/Game/Scripts/UI/Sub/PageHeadbar.cs @@ -20,10 +20,14 @@ namespace Game private readonly Dictionary>> _hitBuffDict = new Dictionary>>(); + private readonly Dictionary> _interactDict = + new Dictionary>(); + protected override void OnCreate() { CreateUI(false); } + protected override void OnOpen() { //打开时创建所有非主角实体的血条 @@ -37,6 +41,7 @@ namespace Game SetHpBar(entity.ID(), true); SetHitNum(entity.ID(), true); + SetInteract(entity.ID(), true); } EventManager.Instance.AddEvent(EEvent.EntityAlive, OnEntityAlive); @@ -93,7 +98,7 @@ namespace Game { var headBarItem = kvp.Value; var posScreen = GetScreenPos(Util.EntityViewPos(entity)); - headBarItem.MComponent.SetPosition(posScreen.x, posScreen.y - 80, posScreen.z); + headBarItem.Component.SetPosition(posScreen.x, posScreen.y - 80, posScreen.z); } } @@ -106,7 +111,7 @@ namespace Game var posScreen = GetScreenPos(Util.EntityViewPos(entity)); foreach (var item in hitNumList) { - item.MComponent.SetPosition(posScreen.x, posScreen.y, posScreen.z); + item.Component.SetPosition(posScreen.x, posScreen.y, posScreen.z); } } } @@ -120,10 +125,20 @@ namespace Game var posScreen = GetScreenPos(Util.EntityViewPos(entity)); foreach (var item in hitNumList) { - item.MComponent.SetPosition(posScreen.x, posScreen.y - 40, posScreen.z); + item.Component.SetPosition(posScreen.x, posScreen.y - 40, posScreen.z); } } } + foreach (var kvp in _interactDict) + { + var entity = Util.GetEntity(kvp.Key); + if (entity != null) + { + var interactItem = kvp.Value; + var posScreen = GetScreenPos(Util.EntityViewPos(entity)); + interactItem.Component.SetPosition(posScreen.x, posScreen.y - 80, posScreen.z); + } + } } /// @@ -157,7 +172,7 @@ namespace Game if (hp.DmgShowTime <= 0) { hp.DmgShowTime = 0; - var lastItem = hitNumList[hitNumList.Count - 1].MComponent as ViewHitNum; + var lastItem = hitNumList[hitNumList.Count - 1].Component as ViewHitNum; lastItem.m_step2.Play(); if (GameRandom.Roll(0.5f)) { @@ -178,7 +193,7 @@ namespace Game } var item = hitNumList[i]; - var hitInfo = hitNumList[i].MComponent as ViewHitNum; + var hitInfo = hitNumList[i].Component as ViewHitNum; if (!hitInfo.m_step2.playing) { item.Destroy(); @@ -212,7 +227,7 @@ namespace Game for (int i = hitNumList.Count - 1; i >= 0; i--) { var item = hitNumList[i]; - var hitInfo = hitNumList[i].MComponent as ViewHitBuff; + var hitInfo = hitNumList[i].Component as ViewHitBuff; if (entity.pause.IsPause) { hitInfo.m_step1.SetPaused(true); @@ -239,6 +254,43 @@ namespace Game SetHpBar(param.Entity, param.IsAlive); SetHitNum(param.Entity, param.IsAlive); + SetInteract(param.Entity, param.IsAlive); + } + + private void SetInteract(int entityID, bool isAlive = true) + { + var entity = Util.GetEntity(entityID); + if (!entity.hasInteract) + { + return; + } + + if (isAlive) + { + if (!_interactDict.ContainsKey(entityID)) + { + var interactBar = UIManager.Instance.Creator.CreateUIItem(ViewInteract.URL); + _interactDict[entityID] = interactBar; + var interactComp = interactBar.Component; + + var interact = entity.interact; + BindData(interact.IsActive, + (_, now) => { interactComp.m_showInteract.selectedIndex = now ? 1 : 0; }); + BindData(interact.IsTarget, + (_, now) => { interactComp.m_isTarget.selectedIndex = now ? 1 : 0; }); + } + } + else + { + if (_interactDict.ContainsKey(entityID)) + { + _interactDict[entityID].Destroy(); + _interactDict.Remove(entityID); + var interact = entity.interact; + UnbindData(interact.IsActive); + UnbindData(interact.IsTarget); + } + } } private void SetHitNum(int entityID, bool isAlive = true) @@ -274,9 +326,8 @@ namespace Game private void SetHpBar(int entityID, bool isAlive = true) { var entity = Util.GetEntity(entityID); - if (entity.IsMaster()) + if (!entity.hasHp) { - //排除主角 return; } @@ -287,7 +338,7 @@ namespace Game //创建血条UI var hpBar = UIManager.Instance.Creator.CreateUIItem(Viewc_blood.URL); _hpBarDict[entityID] = hpBar; - var hpComp = hpBar.MComponent; + var hpComp = hpBar.Component; if (entity.hasHp) { var hp = entity.hp; @@ -352,14 +403,6 @@ namespace Game } }); } - - if (entity.hasInteract) - { - var interact = entity.interact; - BindData(interact.IsActive, (_, now) => { hpComp.m_showInteract.selectedIndex = now ? 1 : 0; }); - BindData(interact.IsTarget, - (_, now) => { hpComp.m_Interact.m_isTarget.selectedIndex = now ? 1 : 0; }); - } } } else @@ -387,13 +430,6 @@ namespace Game UnbindData(ai.IsHungryFull); UnbindData(ai.AttackPermit); } - - if (entity.hasInteract) - { - var interact = entity.interact; - UnbindData(interact.IsActive); - UnbindData(interact.IsTarget); - } } } } @@ -422,14 +458,14 @@ namespace Game { hp.LastDmg = dmg; var hitNum = UIManager.Instance.Creator.CreateUIItem(ViewHitNum.URL); - var item = hitNum.MComponent as ViewHitNum; + var item = hitNum.Component as ViewHitNum; hitList.Add(hitNum); targetItem = item; } else { hp.LastDmg += dmg; - targetItem = hitList[hitList.Count - 1].MComponent as ViewHitNum; + targetItem = hitList[hitList.Count - 1].Component as ViewHitNum; } targetItem.m_num.text = $"{hp.LastDmg}"; @@ -447,7 +483,7 @@ namespace Game var hitList = _hitBuffDict[entityID]; var hitNum = UIManager.Instance.Creator.CreateUIItem(ViewHitBuff.URL); hitList.Add(hitNum); - var item = hitNum.MComponent as ViewHitBuff; + var item = hitNum.Component as ViewHitBuff; item.m_name.text = text; item.m_step1.Play(); } diff --git a/client/Assets/Game/Scripts/UI/UIPoolManager.cs b/client/Assets/Game/Scripts/UI/UIPoolManager.cs index c047591..18540e6 100644 --- a/client/Assets/Game/Scripts/UI/UIPoolManager.cs +++ b/client/Assets/Game/Scripts/UI/UIPoolManager.cs @@ -5,14 +5,14 @@ namespace Game public class UIPoolItem : ObjectPoolItemBase { } public class UIPoolItem : UIPoolItem where T : GComponent, new() { - public T MComponent; + public T Component; protected override void OnCreate() { - MComponent.visible = true; + Component.visible = true; } protected override void OnDestroy() { - MComponent.visible = false; + Component.visible = false; } } public class UIPoolManager : ObjectPoolBase @@ -25,10 +25,10 @@ namespace Game var contentItem = UIPackage.GetItemByURL(url); var pkgName = contentItem.owner.name; var compName = contentItem.name; - string typeName = $"{contentItem.owner.name}_{contentItem.name}"; + var typeName = $"{contentItem.owner.name}_{contentItem.name}"; var poolObj = Create>(typeName, (item) => { - item.MComponent = CreateUIComponent(pkgName, compName) as T; + item.Component = CreateUIComponent(pkgName, compName) as T; }); return poolObj; } diff --git a/client/Assets/Game/Scripts/UI/_ViewGen/Battle/ViewHeadbar.cs b/client/Assets/Game/Scripts/UI/_ViewGen/Battle/ViewHeadbar.cs index e3bb4b5..5d7a049 100644 --- a/client/Assets/Game/Scripts/UI/_ViewGen/Battle/ViewHeadbar.cs +++ b/client/Assets/Game/Scripts/UI/_ViewGen/Battle/ViewHeadbar.cs @@ -12,6 +12,7 @@ namespace Game.Battle public Viewc_blood m_c_blood; public ViewHitNum m_c_hitNum; public ViewHitBuff m_c_hitBuff; + public ViewInteract m_c_Interact; public const string URL = "ui://2qo7xpdcoi571q"; @@ -33,6 +34,7 @@ namespace Game.Battle m_c_blood = (Viewc_blood)this.GetChild("c_blood"); m_c_hitNum = (ViewHitNum)this.GetChild("c_hitNum"); m_c_hitBuff = (ViewHitBuff)this.GetChild("c_hitBuff"); + m_c_Interact = (ViewInteract)this.GetChild("c_Interact"); } } } \ No newline at end of file diff --git a/client/Assets/Game/Scripts/UI/_ViewGen/Battle/ViewInteract.cs b/client/Assets/Game/Scripts/UI/_ViewGen/Battle/ViewInteract.cs index a2495f7..72094e3 100644 --- a/client/Assets/Game/Scripts/UI/_ViewGen/Battle/ViewInteract.cs +++ b/client/Assets/Game/Scripts/UI/_ViewGen/Battle/ViewInteract.cs @@ -8,6 +8,7 @@ namespace Game.Battle public partial class ViewInteract : GComponent { public Controller m_isTarget; + public Controller m_showInteract; public GLoader m_n18; public const string URL = "ui://2qo7xpdco85f57"; @@ -26,6 +27,7 @@ namespace Game.Battle base.ConstructFromXML(xml); m_isTarget = this.GetController("isTarget"); + m_showInteract = this.GetController("showInteract"); m_n18 = (GLoader)this.GetChild("n18"); } } diff --git a/client/Assets/Game/Scripts/UI/_ViewGen/Battle/Viewc_blood.cs b/client/Assets/Game/Scripts/UI/_ViewGen/Battle/Viewc_blood.cs index f3f76e2..300d593 100644 --- a/client/Assets/Game/Scripts/UI/_ViewGen/Battle/Viewc_blood.cs +++ b/client/Assets/Game/Scripts/UI/_ViewGen/Battle/Viewc_blood.cs @@ -12,7 +12,6 @@ namespace Game.Battle public Controller m_showExtra; public Controller m_moduleType; public Controller m_attackStatus; - public Controller m_showInteract; public ViewbloodBarEnemy m_bloodBarEnemy; public ViewshieldBarEnemy m_shieldBarEnemy; public ViewstunBarEnemy m_stunBarEnemy; @@ -21,7 +20,6 @@ namespace Game.Battle public GTextField m_n14; public GGraph m_n15; public GImage m_n17; - public ViewInteract m_Interact; public const string URL = "ui://2qo7xpdcjrii21"; @@ -43,7 +41,6 @@ namespace Game.Battle m_showExtra = this.GetController("showExtra"); m_moduleType = this.GetController("moduleType"); m_attackStatus = this.GetController("attackStatus"); - m_showInteract = this.GetController("showInteract"); m_bloodBarEnemy = (ViewbloodBarEnemy)this.GetChild("bloodBarEnemy"); m_shieldBarEnemy = (ViewshieldBarEnemy)this.GetChild("shieldBarEnemy"); m_stunBarEnemy = (ViewstunBarEnemy)this.GetChild("stunBarEnemy"); @@ -52,7 +49,6 @@ namespace Game.Battle m_n14 = (GTextField)this.GetChild("n14"); m_n15 = (GGraph)this.GetChild("n15"); m_n17 = (GImage)this.GetChild("n17"); - m_Interact = (ViewInteract)this.GetChild("Interact"); } } } \ No newline at end of file diff --git a/client/Assets/Resources/UIRes/Battle_fui.bytes b/client/Assets/Resources/UIRes/Battle_fui.bytes index 086fb8c..81873d5 100644 Binary files a/client/Assets/Resources/UIRes/Battle_fui.bytes and b/client/Assets/Resources/UIRes/Battle_fui.bytes differ diff --git a/uiproject/.objs/workspace.json b/uiproject/.objs/workspace.json index e240612..d74c755 100644 --- a/uiproject/.objs/workspace.json +++ b/uiproject/.objs/workspace.json @@ -2,7 +2,7 @@ "hidden_packages": [], "active_doc": [ "2qo7xpdc", - "teeb53" + "jrii24" ], "expanded_nodes": [ "6tegmf7n", diff --git a/uiproject/assets/Battle/Headbar/Comp/Interact.xml b/uiproject/assets/Battle/Headbar/Comp/Interact.xml index 3079cc0..95f6871 100644 --- a/uiproject/assets/Battle/Headbar/Comp/Interact.xml +++ b/uiproject/assets/Battle/Headbar/Comp/Interact.xml @@ -1,8 +1,10 @@ + + diff --git a/uiproject/assets/Battle/Headbar/Comp/c_blood.xml b/uiproject/assets/Battle/Headbar/Comp/c_blood.xml index e7b540d..44dcd4d 100644 --- a/uiproject/assets/Battle/Headbar/Comp/c_blood.xml +++ b/uiproject/assets/Battle/Headbar/Comp/c_blood.xml @@ -2,18 +2,17 @@ - - + + - - + - + - + @@ -23,11 +22,11 @@ - + - + @@ -40,8 +39,5 @@ - - - \ No newline at end of file diff --git a/uiproject/assets/Battle/Headbar/Headbar.xml b/uiproject/assets/Battle/Headbar/Headbar.xml index 2e31cba..9da4f4b 100644 --- a/uiproject/assets/Battle/Headbar/Headbar.xml +++ b/uiproject/assets/Battle/Headbar/Headbar.xml @@ -2,11 +2,12 @@ - + - - - + + + + \ No newline at end of file