Untitled
unknown
csharp
a year ago
2.5 kB
2
Indexable
Never
public void RefreshMatchScoreAndStatistics() { scoreUIGO.RefreshScore(); if (!isOpen) return; // No need to refresh if the player isn't looking at the scoreboard _playersStatistics.Clear(); foreach (var player in PhotonNetwork.CurrentRoom.Players) _playersStatistics.Add(player.Value); // Hiding all scoreboard slots, not deleting them, so we don't instantiate/delete all the time foreach (ScoreboardElementGO scoreboardSlot in _scoreboardSlots) scoreboardSlot.Reset(); int hostPingForBots = 0; _playerBotStatistics.Clear(); foreach (Player player in _playersStatistics) { if (player.CustomProperties[PhotonKeys.TEAM] == null) continue; // Property not set yet if ((Teams)(int)player.CustomProperties[PhotonKeys.TEAM] == Teams.NONE) continue; // Listing in the scoreboard only players who picked a team PlayerBotScoreboardData playerBotStatistic = new PlayerBotScoreboardData(player); // Assigning each field of the data holder // Using the host's ping for all bots if (player.IsMasterClient) hostPingForBots = (int)player.CustomProperties[PhotonKeys.PING]; _playerBotStatistics.Add(playerBotStatistic); } // Adding all bots foreach (Bot bot in BotManager.instance.bots) { PlayerBotScoreboardData playerBotStatistic = new PlayerBotScoreboardData(bot); _playerBotStatistics.Add(playerBotStatistic); } // Most kills at the top _playerBotStatistics = _playerBotStatistics.OrderByDescending(x => x.kills).ToList(); for (byte i = 0; i < _scoreboardSlots.Count; i++) { if (i >= _playerBotStatistics.Count) break; _scoreboardSlots[i].SetupSlot(_playerBotStatistics[i]); // Setting all text values on the UI for the slot string nickname = _playerBotStatistics[i].nickname; // Need a real reference when using delegates, otherwise doesn't work and it uses the last one that got registered _scoreboardSlots[i].ban_button.onClick.AddListener(delegate { Ban_button(nickname); } ); } // Hiding all slots that have not been used for (byte i = 0; i < _scoreboardSlots.Count; i++) if (!_scoreboardSlots[i].setup && _scoreboardSlots[i].gameObject.activeSelf) _scoreboardSlots[i].gameObject.SetActive(false); }