Skip to content

Commit 19cdd8b

Browse files
committed
removed double ifs
1 parent 0eba777 commit 19cdd8b

File tree

1 file changed

+17
-21
lines changed

1 file changed

+17
-21
lines changed

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

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -97,14 +97,12 @@ protected virtual void ReinitializeProgressBars()
9797
{
9898
var clientId = progressTracker.Key;
9999
var progress = progressTracker.Value.Progress;
100-
if (clientId != NetworkManager.Singleton.LocalClientId)
100+
if (clientId != NetworkManager.Singleton.LocalClientId && m_ClientIdToProgressBarsIndex.ContainsKey(clientId))
101101
{
102-
if (m_ClientIdToProgressBarsIndex.ContainsKey(clientId))
103-
{
104-
progress.OnValueChanged -= (value, newValue) =>
105-
m_OtherPlayersProgressBars[m_ClientIdToProgressBarsIndex[clientId]].value = newValue;
106-
}
102+
progress.OnValueChanged -= (value, newValue) =>
103+
m_OtherPlayersProgressBars[m_ClientIdToProgressBarsIndex[clientId]].value = newValue;
107104
}
105+
108106
}
109107
// clear map
110108
m_ClientIdToProgressBarsIndex.Clear();
@@ -128,23 +126,21 @@ protected virtual void UpdateProgressBars(bool isInitializing)
128126
{
129127
var clientId = progressTracker.Key;
130128
var progress = progressTracker.Value.Progress;
131-
if (clientId != NetworkManager.Singleton.LocalClientId)
129+
if (clientId != NetworkManager.Singleton.LocalClientId && !m_ClientIdToProgressBarsIndex.ContainsKey(clientId))
132130
{
133-
if (!m_ClientIdToProgressBarsIndex.ContainsKey(clientId))
131+
if (m_ClientIdToProgressBarsIndex.Count < m_OtherPlayersProgressBars.Count)
132+
{
133+
m_ClientIdToProgressBarsIndex[clientId] = m_ClientIdToProgressBarsIndex.Count;
134+
135+
// set progress bar to 0 if initializing, else set it to its last known value
136+
m_OtherPlayersProgressBars[m_ClientIdToProgressBarsIndex[clientId]].value = isInitializing ? 0 : progress.Value;
137+
progress.OnValueChanged += (value, newValue) =>
138+
m_OtherPlayersProgressBars[m_ClientIdToProgressBarsIndex[clientId]].value = newValue;
139+
m_OtherPlayersProgressBars[m_ClientIdToProgressBarsIndex[clientId]].gameObject.SetActive(true);
140+
}
141+
else
134142
{
135-
if (m_ClientIdToProgressBarsIndex.Count < m_OtherPlayersProgressBars.Count)
136-
{
137-
m_ClientIdToProgressBarsIndex[clientId] = m_ClientIdToProgressBarsIndex.Count;
138-
// set progress bar to 0 if initializing, else set it to its last known value
139-
m_OtherPlayersProgressBars[m_ClientIdToProgressBarsIndex[clientId]].value = isInitializing ? 0 : progress.Value;
140-
progress.OnValueChanged += (value, newValue) =>
141-
m_OtherPlayersProgressBars[m_ClientIdToProgressBarsIndex[clientId]].value = newValue;
142-
m_OtherPlayersProgressBars[m_ClientIdToProgressBarsIndex[clientId]].gameObject.SetActive(true);
143-
}
144-
else
145-
{
146-
throw new Exception("There are not enough progress bars to track the progress of all the players.");
147-
}
143+
throw new Exception("There are not enough progress bars to track the progress of all the players.");
148144
}
149145
}
150146
}

0 commit comments

Comments
 (0)