Skip to content

fix: loading progress bars mismatch [MTT-3616] #654

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 20, 2022
Merged
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 @@ -3,6 +3,7 @@
using System.Collections.Generic;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.Assertions;
using UnityEngine.UI;

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

void Start()
Expand Down Expand Up @@ -151,6 +153,12 @@ void ReinitializeProgressBars()
RemoveOtherPlayerProgressBar(clientId);
}

for (var i = 0; i < m_OtherPlayersProgressBars.Count; i++)
{
m_OtherPlayersProgressBars[i].gameObject.SetActive(false);
m_OtherPlayerNamesTexts[i].gameObject.SetActive(false);
}

var index = 0;

foreach (var progressTracker in m_LoadingProgressManager.ProgressTrackers)
Expand All @@ -166,12 +174,14 @@ void ReinitializeProgressBars()
protected virtual void UpdateOtherPlayerProgressBar(ulong clientId, int progressBarIndex)
{
m_LoadingProgressBars[clientId].ProgressBar = m_OtherPlayersProgressBars[progressBarIndex];
m_LoadingProgressBars[clientId].ProgressBar.gameObject.SetActive(true);
m_LoadingProgressBars[clientId].NameText = m_OtherPlayerNamesTexts[progressBarIndex];
m_LoadingProgressBars[clientId].NameText.gameObject.SetActive(true);
}

protected virtual void AddOtherPlayerProgressBar(ulong clientId, NetworkedLoadingProgressTracker progressTracker)
{
if (m_LoadingProgressBars.Count < m_OtherPlayersProgressBars.Count)
if (m_LoadingProgressBars.Count < m_OtherPlayersProgressBars.Count && m_LoadingProgressBars.Count < m_OtherPlayerNamesTexts.Count)
{
var index = m_LoadingProgressBars.Count;
m_LoadingProgressBars[clientId] = new LoadingProgressBar(m_OtherPlayersProgressBars[index], m_OtherPlayerNamesTexts[index]);
Expand Down