Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ public class ClientCharacterVisualization : NetworkBehaviour
int m_DeadStateTriggerID;
int m_HitStateTriggerID;

event Action Destroyed;

/// <inheritdoc />
public override void NetworkStart()
{
Expand Down Expand Up @@ -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);
}
};
}
}
}
Expand Down Expand Up @@ -153,6 +168,8 @@ private void OnDestroy()
m_NetState.OnStopChargingUpClient -= OnStoppedChargingUp;
m_NetState.IsStealthy.OnValueChanged -= OnStealthyChanged;
}

Destroyed?.Invoke();
}

private void OnPerformHitReaction()
Expand Down
30 changes: 20 additions & 10 deletions Assets/BossRoom/Scripts/Client/UI/PartyHUD.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
}

/// <summary>
/// Remove an ally from the PartyHUD UI.
/// </summary>
/// <param name="id"> NetworkObjectID of the ally. </param>
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;
}
}
}
}
}