You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

73 lines
1.8 KiB

5 years ago
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using TMPro;
  5. using Networking;
  6. using Networking.Server;
  7. public class LobbyUIController : MonoBehaviour
  8. {
  9. [SerializeField]
  10. private ClientList Clients;
  11. [SerializeField]
  12. private string SceneToStart;
  13. [Header("UI Elements")]
  14. [SerializeField]
  15. private TextMeshProUGUI IPText;
  16. [SerializeField]
  17. private Transform Content;
  18. [SerializeField]
  19. private GameObject ClientTag;
  20. [SerializeField]
  21. private Color[] PlayerColors;
  22. [SerializeField]
  23. private string[] PlayerAnimals;
  24. // Start is called before the first frame update
  25. void Start()
  26. {
  27. IPText.text = "Lobby - " + Networking.Utility.GetIP(Networking.Utility.ADDRESSFAM.IPv4);
  28. }
  29. private void OnEnable()
  30. {
  31. Clients.OnClientsChange += DisplayClients;
  32. DisplayClients(Clients.ConnectedClients);
  33. }
  34. private void OnDisable()
  35. {
  36. Clients.OnClientsChange -= DisplayClients;
  37. }
  38. private void DisplayClients(List<ClientData> data)
  39. {
  40. Debug.Log("Updating Connected Clients");
  41. foreach (Transform child in Content)
  42. if (child.gameObject != ClientTag)
  43. Destroy(child.gameObject);
  44. for (int i = 0; i < Clients.ConnectedClients.Count; i++)
  45. {
  46. ClientData client = Clients.ConnectedClients[i];
  47. GameObject clientObject = Instantiate(ClientTag, Content);
  48. TextMeshProUGUI clientText = clientObject.GetComponent<TextMeshProUGUI>();
  49. clientText.text = client.Name + " the " + client.characterAnimal;
  50. clientText.color = client.Color;
  51. clientObject.SetActive(true);
  52. }
  53. }
  54. public void OnClick_StartGame()
  55. {
  56. UnityEngine.SceneManagement.SceneManager.LoadScene(SceneToStart);
  57. }
  58. }