/// <summary> /// Add a player to the list of players in this lobby /// </summary> /// <param name="steamId">The SteamId of the player to add to the list</param> private void AddPlayer(SteamId steamId) { for (int i = 0; i < playerList.Count; ++i) { var player = playerList[i]; if (player.steamId.Value == steamId.Value) { // Already have that player listed nothing else to do UpdateItem(player); return; } } var playerListItemData = new PlayerListItemData { listItem = GameObject.Instantiate <PlayerListEntry>(playerListEntryTemplate, players.content), steamId = steamId, }; playerListItemData.listItem.gameObject.SetActive(true); UpdateItem(playerListItemData); playerListItemData.nextUpdate = Time.time + 5.0f + UnityEngine.Random.Range(0.0f, 1.0f); playerList.Add(playerListItemData); RepositionItems(); }
/// <summary> /// Update a specific server's details on the server list. /// </summary> /// <param name="option">The server display information to update</param> private void UpdateItem(PlayerListItemData option, Friend friend = default(Friend)) { option.steamId = friend.Id; option.listItem.steamId.text = option.steamId.Value.ToString(); option.playerName = friend.Name; option.listItem.playerName.text = option.playerName; //ping //isClientConnected }
/// <summary> /// Remove a player from the list /// </summary> /// <param name="item">Lobby listItemData to remove</param> private void RemovePlayer(PlayerListItemData item) { Destroy(item.listItem.gameObject); playerList.Remove(item); RepositionItems(); }