/// <summary> /// Adds player to the playe list and sets it up /// </summary> /// <param name="playerName">Username of the player that should be added</param> /// <param name="state">State of the player that is beeing added</param> public void AddPlayer(string playerName, PlayerListItem.PlayerState state) { GameObject go = Instantiate(playerListItemPrefab); go.transform.SetParent(transform, false); PlayerListItem player = go.GetComponent <PlayerListItem>(); player.playerName = playerName; player.state = state; player.SetUp(); }
/// <summary> /// Primes the lobby by filling up the player list /// </summary> /// <param name="players">Dictionary with all the players connected to the server</param> public void Prime(Dictionary <string, PlayerListItem.PlayerState> players) { foreach (KeyValuePair <string, PlayerListItem.PlayerState> kvp in players) { GameObject go = Instantiate(playerListItemPrefab); go.transform.SetParent(transform, false); PlayerListItem player = go.GetComponent <PlayerListItem>(); player.playerName = kvp.Key; player.state = kvp.Value; player.SetUp(); } }
/// <summary> /// Update players state given as parameter /// </summary> /// <param name="playerName">Username of the player that should be updated in the list</param> /// <param name="state">New state of the player</param> public void UpdatePlayer(string playerName, PlayerListItem.PlayerState state) { foreach (Transform child in transform) { PlayerListItem player = child.gameObject.GetComponent <PlayerListItem>(); if (player.playerName == playerName) { player.state = state; player.SetUp(); break; } } }