Skip to content

Commit 5044c7f

Browse files
fix: loading progress bars mismatch (#654)
* making sure the right progress bars are deactivated and activated when starting a new loading screen
1 parent f3557c7 commit 5044c7f

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

Packages/com.unity.multiplayer.samples.coop/Utilities/SceneManagement/ClientLoadingScreen.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System.Collections.Generic;
44
using Unity.Netcode;
55
using UnityEngine;
6+
using UnityEngine.Assertions;
67
using UnityEngine.UI;
78

89
namespace Unity.Multiplayer.Samples.Utilities
@@ -65,6 +66,7 @@ public void UpdateProgress(float value, float newValue)
6566
void Awake()
6667
{
6768
DontDestroyOnLoad(this);
69+
Assert.AreEqual(m_OtherPlayersProgressBars.Count, m_OtherPlayerNamesTexts.Count, "There should be the same number of progress bars and name labels");
6870
}
6971

7072
void Start()
@@ -151,6 +153,12 @@ void ReinitializeProgressBars()
151153
RemoveOtherPlayerProgressBar(clientId);
152154
}
153155

156+
for (var i = 0; i < m_OtherPlayersProgressBars.Count; i++)
157+
{
158+
m_OtherPlayersProgressBars[i].gameObject.SetActive(false);
159+
m_OtherPlayerNamesTexts[i].gameObject.SetActive(false);
160+
}
161+
154162
var index = 0;
155163

156164
foreach (var progressTracker in m_LoadingProgressManager.ProgressTrackers)
@@ -166,12 +174,14 @@ void ReinitializeProgressBars()
166174
protected virtual void UpdateOtherPlayerProgressBar(ulong clientId, int progressBarIndex)
167175
{
168176
m_LoadingProgressBars[clientId].ProgressBar = m_OtherPlayersProgressBars[progressBarIndex];
177+
m_LoadingProgressBars[clientId].ProgressBar.gameObject.SetActive(true);
169178
m_LoadingProgressBars[clientId].NameText = m_OtherPlayerNamesTexts[progressBarIndex];
179+
m_LoadingProgressBars[clientId].NameText.gameObject.SetActive(true);
170180
}
171181

172182
protected virtual void AddOtherPlayerProgressBar(ulong clientId, NetworkedLoadingProgressTracker progressTracker)
173183
{
174-
if (m_LoadingProgressBars.Count < m_OtherPlayersProgressBars.Count)
184+
if (m_LoadingProgressBars.Count < m_OtherPlayersProgressBars.Count && m_LoadingProgressBars.Count < m_OtherPlayerNamesTexts.Count)
175185
{
176186
var index = m_LoadingProgressBars.Count;
177187
m_LoadingProgressBars[clientId] = new LoadingProgressBar(m_OtherPlayersProgressBars[index], m_OtherPlayerNamesTexts[index]);

0 commit comments

Comments
 (0)