1
Fork 0
mirror of https://github.com/Steffo99/better-tee.git synced 2024-11-22 23:34:18 +00:00
better-tee/Assets/Old/Code/Viewer/LobbyController.cs

52 lines
1.8 KiB
C#
Raw Normal View History

2019-09-21 00:24:30 +00:00
using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
namespace BetterTee.Viewer
{
public class LobbyController : MonoBehaviour
{
[Header("Objects")]
public Canvas canvas = null;
public EventSystem eventSystem = null;
public Action startGameAction = null;
public Text lobbyText = null;
2019-09-22 17:58:06 +00:00
public InputField gameSettingsField = null;
2019-09-21 00:24:30 +00:00
public StartGameBtn startGameBtn = null;
[Header("Prefabs")]
public GameObject lobbyTextPrefab;
2019-09-22 17:58:06 +00:00
public GameObject gameSettingsFieldPrefab;
2019-09-21 00:24:30 +00:00
public GameObject startGameBtnPrefab;
protected void Start() {
canvas = GameObject.FindGameObjectWithTag("Canvas")?.GetComponent<Canvas>();
eventSystem = GameObject.FindGameObjectWithTag("EventSystem")?.GetComponent<EventSystem>();
lobbyText = Instantiate(lobbyTextPrefab, canvas.transform).GetComponent<Text>();
2019-09-22 17:58:06 +00:00
gameSettingsField = Instantiate(gameSettingsFieldPrefab, canvas.transform).GetComponent<InputField>();
2019-09-21 00:24:30 +00:00
startGameBtn = Instantiate(startGameBtnPrefab, canvas.transform).GetComponent<StartGameBtn>();
startGameBtn.lobbyController = this;
}
2019-09-22 17:58:06 +00:00
public void OnLobbyStatusChange(ConnectedPlayerData[] players, ConnectedViewerData[] viewers, bool canStart) {
gameSettingsField.interactable = true;
startGameBtn.GetComponent<Button>().interactable = canStart;
2019-09-21 00:24:30 +00:00
}
public void OnStartGameBtnPress() {
startGameAction();
}
protected void OnDestroy() {
Destroy(lobbyText.gameObject);
2019-09-22 17:58:06 +00:00
Destroy(gameSettingsField.gameObject);
Destroy(startGameBtn.gameObject);
2019-09-21 00:24:30 +00:00
}
}
}