diff --git a/Assets/BossRoom/Scripts/Client/Game/Character/ClientCharacterVisualization.cs b/Assets/BossRoom/Scripts/Client/Game/Character/ClientCharacterVisualization.cs index 8152f418c..68fde6128 100644 --- a/Assets/BossRoom/Scripts/Client/Game/Character/ClientCharacterVisualization.cs +++ b/Assets/BossRoom/Scripts/Client/Game/Character/ClientCharacterVisualization.cs @@ -48,6 +48,8 @@ public class ClientCharacterVisualization : NetworkBehaviour int m_DeadStateTriggerID; int m_HitStateTriggerID; + event Action Destroyed; + /// public override void NetworkStart() { @@ -120,6 +122,19 @@ public override void NetworkStart() else { m_PartyHUD.SetAllyData(m_NetState); + + // getting our parent's NetworkObjectID for PartyHUD removal on Destroy + var parentNetworkObjectID = m_NetState.NetworkObjectId; + + // once this object is destroyed, remove this ally from the PartyHUD UI + // NOTE: architecturally this will be refactored + Destroyed += () => + { + if (m_PartyHUD != null) + { + m_PartyHUD.RemoveAlly(parentNetworkObjectID); + } + }; } } } @@ -153,6 +168,8 @@ private void OnDestroy() m_NetState.OnStopChargingUpClient -= OnStoppedChargingUp; m_NetState.IsStealthy.OnValueChanged -= OnStealthyChanged; } + + Destroyed?.Invoke(); } private void OnPerformHitReaction() diff --git a/Assets/BossRoom/Scripts/Client/UI/PartyHUD.cs b/Assets/BossRoom/Scripts/Client/UI/PartyHUD.cs index 8ea23f454..2d1e9a91e 100644 --- a/Assets/BossRoom/Scripts/Client/UI/PartyHUD.cs +++ b/Assets/BossRoom/Scripts/Client/UI/PartyHUD.cs @@ -33,7 +33,7 @@ public class PartyHUD : MonoBehaviour [SerializeField] private Sprite[] m_ClassSymbols; - // track a list of hero (slot 0) + allies + // track a list of hero (slot 0) + allies private ulong[] m_PartyIds; // track Hero's target to show when it is the Hero or an ally @@ -113,15 +113,6 @@ public void SetAllyHealth(ulong id, int hp) m_PartyHealthSliders[slot].value = hp; } - public void SetAllyName(ulong id, string name) - { - int slot = FindOrAddAlly(id); - // do nothing if not in a slot - if (slot == -1) { return; } - - m_PartyNames[slot].text = name; - } - private void OnHeroSelectionChanged(ulong prevTarget, ulong newTarget) { SetHeroSelectFX(m_CurrentTarget, false); @@ -205,5 +196,24 @@ private int FindOrAddAlly(ulong id, bool dontAdd = false) // this should not happen unless there are too many players - we didn't find the ally or a slot return -1; } + + /// + /// Remove an ally from the PartyHUD UI. + /// + /// NetworkObjectID of the ally. + public void RemoveAlly(ulong id) + { + for (int i = 0; i < m_PartyIds.Length; i++) + { + // if this ID is in the list, return the slot index + if (m_PartyIds[i] == id) + { + m_AllyPanel[i - 1].SetActive(false); + // and save ally ID to party array + m_PartyIds[i] = 0; + return; + } + } + } } }