56 lines
2.3 KiB
C#
56 lines
2.3 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using Photon.Realtime;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
|
|
public class LeaderboardTDM : MonoBehaviour
|
|
{
|
|
public Dictionary<string, List<PlayerNetwork>> Teams;
|
|
|
|
public Transform[] TeamParents;
|
|
public void Populate(PlayerNetwork[] list){
|
|
//Teamify
|
|
Teams = new Dictionary<string, List<PlayerNetwork>>();
|
|
foreach(PlayerNetwork player in list){
|
|
if(Teams.ContainsKey(player.partyname)){
|
|
Teams[player.partyname].Add(player);
|
|
}else{
|
|
Teams.Add(player.partyname, new List<PlayerNetwork>(){player});
|
|
}
|
|
}
|
|
|
|
for(int i=0; i < TeamParents.Length; i++){
|
|
bool withinRange = (Teams.Keys.Count > i);
|
|
TeamParents[i].gameObject.SetActive(withinRange);
|
|
unsortedTeamScores = new Dictionary<string, int>();
|
|
if(withinRange){
|
|
TeamParents[i].GetChild(0).GetComponent<TMP_Text>().text = Teams.Keys.ElementAt(i);
|
|
int score =0;
|
|
|
|
for(int ii = 0; ii < TeamParents[i].GetChild(2).childCount; ii++){
|
|
bool playerItemsWithinRange = Teams.Values.ElementAt(i).Count > ii;
|
|
Transform playerItemTransform = TeamParents[i].GetChild(2).GetChild(ii);
|
|
playerItemTransform.gameObject.SetActive(playerItemsWithinRange);
|
|
if(!playerItemsWithinRange){continue;}
|
|
|
|
PlayerNetwork player = Teams.Values.ElementAt(i)[ii];
|
|
playerItemTransform.GetChild(0).GetComponent<TMP_Text>().text = player.username;
|
|
playerItemTransform.GetChild(1).GetComponent<TMP_Text>().text = player.kills.ToString();
|
|
playerItemTransform.GetChild(2).GetComponent<TMP_Text>().text = player.deaths.ToString();
|
|
playerItemTransform.GetChild(3).GetComponent<TMP_Text>().text = player.assists.ToString();
|
|
|
|
score+= player.kills;
|
|
}
|
|
|
|
unsortedTeamScores.Add(Teams.Keys.ElementAt(i), score);
|
|
|
|
TeamParents[i].GetChild(1).GetComponent<TMP_Text>().text = (score * 10).ToString("n0");
|
|
}
|
|
}
|
|
}
|
|
|
|
public static Dictionary<string, int> unsortedTeamScores;
|
|
}
|