/// <summary> /// Sets all the Text and Image values based on the input `info` /// </summary> /// <param name="info">PlayerListInfo type, all the data about this player</param> public virtual void SetContents(PlayerListInfo info) { userId = info.userId; playerNameText.text = userId.Split(':')[0]; if (location != null) { sceneName = "Unknown Location"; if (info.sceneIndex > 9999 && hideLocationIfNotSet == true) { location.gameObject.SetActive(false); } else { location.gameObject.SetActive(true); if (info.sceneIndex == -1) { sceneName = "Lobby"; } else if (info.sceneIndex < NetworkManager.networkManager.database.storedScenesData.Count) { sceneName = NetworkManager.networkManager.database.storedScenesData.Find(x => x.index == info.sceneIndex).sceneName; } } location.text = sceneName; } }
// To add the player to the room of they clicked private void AddPlayerToRoom(Player newPlayer) { PlayerListInfo player = Instantiate(playerListingPrefabs, content); if (player != null) { player.SetRoomInfo(newPlayer); } players.Add(player); }
/// <summary> /// Creates a child gameobject with all the settings found in the input `PlayerListInfo` object. /// Also makes sure the scale and positioning is correct. /// </summary> /// <param name="player">PlayerListInfo type, the information for this player to display</param> public virtual void AddPlayer(PlayerListInfo player) { if (debugging == true) { Debug.Log("PLAYERLIST - Adding player: " + player.userId); } GameObject obj = Instantiate(playerJoinObject) as GameObject; obj.transform.SetParent(content.transform); obj.transform.localPosition = Vector3.zero; obj.transform.localScale = new Vector3(1, 1, 1); obj.GetComponent <PlayerListObject>().SetContents(player); }
/// <summary> /// Find the child object that matches the input `info` and calls the `SetContents` function /// with the input `info` on it. /// </summary> /// <param name="info">PlayerListInfo type, the information for a given player</param> public virtual void UpdatePlayer(PlayerListInfo info) { if (debugging == true) { Debug.Log("PLAYER LIST- Updating player list with: " + info.userId); } foreach (Transform child in content.transform) { if (child.GetComponent <PlayerListObject>().userId == info.userId) { if (debugging == true) { Debug.Log("PLAYERLIST - Found player, updating: " + info.userId + " sceneIndex: " + info.sceneIndex); } child.GetComponent <PlayerListObject>().SetContents(info); break; } } }
/// <summary> /// Find the child object that matches the User Id of the input player and destroys it. /// </summary> /// <param name="player">PlayerListInfo type, extracts user id from this</param> public virtual void RemovePlayer(PlayerListInfo player) { if (debugging == true) { Debug.Log("PLAYERLIST - Attempting To Remove Player: " + player.userId); } foreach (Transform child in content.transform) { if (child.GetComponent <PlayerListObject>().userId == player.userId) { if (debugging == true) { Debug.Log("PLAYERLIST - Found player, removing: " + player.userId); } Destroy(child.gameObject); break; } } }