@@ -22,36 +22,33 @@ public class PartyHUD : MonoBehaviour
2222 ClientPlayerAvatarRuntimeCollection m_PlayerAvatars ;
2323
2424 [ SerializeField ]
25- private Image m_HeroPortrait ;
25+ Image m_HeroPortrait ;
2626
2727 [ SerializeField ]
28- private GameObject [ ] m_AllyPanel ;
28+ GameObject [ ] m_AllyPanel ;
2929
3030 [ SerializeField ]
31- private TextMeshProUGUI [ ] m_PartyNames ;
31+ TextMeshProUGUI [ ] m_PartyNames ;
3232
3333 [ SerializeField ]
34- private Image [ ] m_PartyClassSymbols ;
34+ Image [ ] m_PartyClassSymbols ;
3535
3636 [ SerializeField ]
37- private Slider [ ] m_PartyHealthSliders ;
37+ Slider [ ] m_PartyHealthSliders ;
3838
3939 [ SerializeField ]
40- private Image [ ] m_PartyHealthGodModeImages ;
40+ Image [ ] m_PartyHealthGodModeImages ;
4141
4242 // track a list of hero (slot 0) + allies
43- private ulong [ ] m_PartyIds ;
44-
45- // track Hero's target to show when it is the Hero or an ally
46- private ulong m_CurrentTarget ;
43+ ulong [ ] m_PartyIds ;
4744
4845 ServerCharacter m_OwnedServerCharacter ;
4946
5047 ClientPlayerAvatar m_OwnedPlayerAvatar ;
5148
52- private Dictionary < ulong , ServerCharacter > m_TrackedAllies = new Dictionary < ulong , ServerCharacter > ( ) ;
49+ Dictionary < ulong , ServerCharacter > m_TrackedAllies = new Dictionary < ulong , ServerCharacter > ( ) ;
5350
54- private ClientInputSender m_ClientSender ;
51+ ClientInputSender m_ClientSender ;
5552
5653 void Awake ( )
5754 {
@@ -150,6 +147,7 @@ void SetAllyData(ClientPlayerAvatar clientPlayerAvatar)
150147
151148 ulong id = serverCharacter . NetworkObjectId ;
152149 int slot = FindOrAddAlly ( id ) ;
150+
153151 // do nothing if not in a slot
154152 if ( slot == - 1 )
155153 {
@@ -189,19 +187,22 @@ void SetUIFromSlotData(int slot, ServerCharacter serverCharacter)
189187#if UNITY_EDITOR || DEVELOPMENT_BUILD
190188 void SetAllyGodModeStatus ( ulong id , bool newValue )
191189 {
192- int slot = FindOrAddAlly ( id ) ;
190+ int slot = FindOrAddAlly ( id , true ) ;
191+
193192 // do nothing if not in a slot
194193 if ( slot == - 1 )
195194 {
196195 return ;
197196 }
197+
198198 m_PartyHealthGodModeImages [ slot ] . gameObject . SetActive ( newValue ) ;
199199 }
200200#endif
201201
202202 void SetAllyHealth ( ulong id , int hp )
203203 {
204- int slot = FindOrAddAlly ( id ) ;
204+ int slot = FindOrAddAlly ( id , true ) ;
205+
205206 // do nothing if not in a slot
206207 if ( slot == - 1 )
207208 {
@@ -211,29 +212,20 @@ void SetAllyHealth(ulong id, int hp)
211212 m_PartyHealthSliders [ slot ] . value = hp ;
212213 }
213214
214- private void OnHeroSelectionChanged ( ulong prevTarget , ulong newTarget )
215+ void OnHeroSelectionChanged ( ulong prevTarget , ulong newTarget )
215216 {
216- SetHeroSelectFX ( m_CurrentTarget , false ) ;
217+ SetHeroSelectFX ( prevTarget , false ) ;
217218 SetHeroSelectFX ( newTarget , true ) ;
218219 }
219220
220221 // Helper to change name appearance for selected or unselected party members
221- // also updates m_CurrentTarget
222- private void SetHeroSelectFX ( ulong target , bool selected )
222+ void SetHeroSelectFX ( ulong target , bool selected )
223223 {
224224 // check id against all party slots
225225 int slot = FindOrAddAlly ( target , true ) ;
226226 if ( slot >= 0 )
227227 {
228228 m_PartyNames [ slot ] . color = selected ? Color . green : Color . white ;
229- if ( selected )
230- {
231- m_CurrentTarget = target ;
232- }
233- else
234- {
235- m_CurrentTarget = 0 ;
236- }
237229 }
238230 }
239231
@@ -244,7 +236,7 @@ public void SelectPartyMember(int slot)
244236 }
245237
246238 // helper to initialize the Allies array - safe to call multiple times
247- private void InitPartyArrays ( )
239+ void InitPartyArrays ( )
248240 {
249241 if ( m_PartyIds == null )
250242 {
@@ -262,16 +254,26 @@ private void InitPartyArrays()
262254
263255 // Helper to find ally slots, returns -1 if no slot is found for the id
264256 // If a slot is available one will be added for this id unless dontAdd=true
265- private int FindOrAddAlly ( ulong id , bool dontAdd = false )
257+ int FindOrAddAlly ( ulong id , bool dontAdd = false )
266258 {
267259 // make sure allies array is ready
268260 InitPartyArrays ( ) ;
269261
262+ if ( id == 0 )
263+ {
264+ // special case: id of 0 is uninitialized party id
265+ return - 1 ;
266+ }
267+
270268 int openslot = - 1 ;
271269 for ( int i = 0 ; i < m_PartyIds . Length ; i ++ )
272270 {
273271 // if this ID is in the list, return the slot index
274- if ( m_PartyIds [ i ] == id ) { return i ; }
272+ if ( m_PartyIds [ i ] == id )
273+ {
274+ return i ;
275+ }
276+
275277 // otherwise, record the first open slot (not slot 0 thats for the Hero)
276278 if ( openslot == - 1 && i > 0 && m_PartyIds [ i ] == 0 )
277279 {
@@ -287,6 +289,7 @@ private int FindOrAddAlly(ulong id, bool dontAdd = false)
287289 {
288290 // activeate the correct ally panel
289291 m_AllyPanel [ openslot - 1 ] . SetActive ( true ) ;
292+
290293 // and save ally ID to party array
291294 m_PartyIds [ openslot ] = id ;
292295 return openslot ;
@@ -315,15 +318,18 @@ void RemoveHero()
315318 /// <param name="id"> NetworkObjectID of the ally. </param>
316319 void RemoveAlly ( ulong id )
317320 {
321+ // remove potential selected state of party member UI
322+ SetHeroSelectFX ( id , false ) ;
323+
318324 for ( int i = 0 ; i < m_PartyIds . Length ; i ++ )
319325 {
320326 // if this ID is in the list, return the slot index
321327 if ( m_PartyIds [ i ] == id )
322328 {
323329 m_AllyPanel [ i - 1 ] . SetActive ( false ) ;
330+
324331 // and save ally ID to party array
325332 m_PartyIds [ i ] = 0 ;
326- return ;
327333 }
328334 }
329335
0 commit comments