|
|
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using TMPro;
- using Networking;
- using Networking.Server;
-
- public class LobbyUIController : MonoBehaviour
- {
-
-
-
- [SerializeField]
- private ConnectionHandler Clients;
-
- [SerializeField]
- private string SceneToStart;
-
- [Header("UI Elements")]
- [SerializeField]
- private TextMeshProUGUI IPText;
-
- [SerializeField]
- private Transform Content;
-
- [SerializeField]
- private GameObject ClientTag;
-
-
- // Start is called before the first frame update
- void Start()
- {
- IPText.text = "Lobby - " + Networking.Utility.GetIP(Networking.Utility.ADDRESSFAM.IPv4);
-
- }
-
- private void OnEnable()
- {
- Clients.OnClientsChange += DisplayClients;
- DisplayClients(Clients.ConnectedClients);
- }
-
- private void OnDisable()
- {
- Clients.OnClientsChange -= DisplayClients;
- }
-
-
- private void DisplayClients(List<ClientData> data)
- {
- Debug.Log("Updating Connected Clients");
- foreach (Transform child in Content)
- if (child.gameObject != ClientTag)
- Destroy(child.gameObject);
-
- foreach (ClientData client in Clients.ConnectedClients)
- {
- GameObject clientObject = Instantiate(ClientTag, Content);
- TextMeshProUGUI clientText = clientObject.GetComponent<TextMeshProUGUI>();
- clientText.text = client.Name;
- clientText.color = client.Color;
- clientObject.SetActive(true);
- }
- }
-
- public void OnClick_StartGame()
- {
- UnityEngine.SceneManagement.SceneManager.LoadScene(SceneToStart);
- }
-
-
- }
|