2018-04-21 12:22:17 +02:00
|
|
|
|
using System.Collections;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using UnityEngine;
|
2018-04-23 13:17:59 +02:00
|
|
|
|
using UnityEngine.SceneManagement;
|
2018-04-23 13:35:56 +02:00
|
|
|
|
using UnityEngine.UI;
|
2018-04-21 12:22:17 +02:00
|
|
|
|
|
2018-04-22 20:10:05 +02:00
|
|
|
|
public class UIController : MonoBehaviour
|
|
|
|
|
{
|
2018-04-22 15:59:14 +02:00
|
|
|
|
|
2018-04-22 19:07:50 +02:00
|
|
|
|
GameObject score;
|
|
|
|
|
GameObject pauseMenu;
|
2018-04-22 00:22:56 +02:00
|
|
|
|
|
2018-04-22 20:10:05 +02:00
|
|
|
|
[SerializeField]
|
|
|
|
|
NotificationManager notifications;
|
|
|
|
|
|
2018-04-22 00:22:56 +02:00
|
|
|
|
[SerializeField]
|
2018-04-23 13:35:56 +02:00
|
|
|
|
GameObject restartUIPanel;
|
2018-04-22 15:59:14 +02:00
|
|
|
|
|
|
|
|
|
[SerializeField]
|
2018-04-22 20:10:05 +02:00
|
|
|
|
HealthbarController healthcontroller;
|
2018-04-22 15:59:14 +02:00
|
|
|
|
|
2018-04-23 21:14:04 +02:00
|
|
|
|
[SerializeField]
|
|
|
|
|
BrakeBarController brakeBarController;
|
|
|
|
|
|
2018-04-24 02:15:58 +02:00
|
|
|
|
[SerializeField]
|
|
|
|
|
GameObject pausedUIPanel;
|
|
|
|
|
|
2018-04-23 13:17:59 +02:00
|
|
|
|
[SerializeField]
|
|
|
|
|
int mainMenuSceneIndex = 0;
|
|
|
|
|
int firstSceneIndex = 1;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void Update() {
|
2018-04-23 16:24:59 +02:00
|
|
|
|
if (Input.GetAxis("Reset") > 0 && GameController.instance.GameEnded()) {
|
2018-04-24 17:48:22 +02:00
|
|
|
|
Restart();
|
2018-04-23 13:17:59 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void ShowPauseMenu() {
|
2018-04-22 05:57:26 +02:00
|
|
|
|
pauseMenu.SetActive(true);
|
2018-04-21 20:47:50 +02:00
|
|
|
|
}
|
2018-04-22 15:59:14 +02:00
|
|
|
|
|
2018-04-23 13:17:59 +02:00
|
|
|
|
public void ClosePauseMenu() {
|
2018-04-22 05:57:26 +02:00
|
|
|
|
pauseMenu.SetActive(false);
|
|
|
|
|
}
|
|
|
|
|
|
2018-04-24 17:48:22 +02:00
|
|
|
|
public void Restart() {
|
|
|
|
|
LoadSceneByIndex(firstSceneIndex);
|
|
|
|
|
}
|
|
|
|
|
|
2018-04-23 13:17:59 +02:00
|
|
|
|
public void LoadSceneByIndex(int index) {
|
2018-04-22 00:22:56 +02:00
|
|
|
|
Debug.Log("Loaded scene " + index);
|
2018-04-23 13:17:59 +02:00
|
|
|
|
SceneManager.LoadScene(index);
|
2018-04-21 22:32:53 +02:00
|
|
|
|
}
|
|
|
|
|
|
2018-04-23 13:17:59 +02:00
|
|
|
|
public void QuitGame() {
|
2018-04-22 00:22:56 +02:00
|
|
|
|
Debug.Log("Quit game");
|
2018-04-21 22:32:53 +02:00
|
|
|
|
Application.Quit();
|
2018-04-22 00:22:56 +02:00
|
|
|
|
}
|
|
|
|
|
|
2018-04-23 13:17:59 +02:00
|
|
|
|
public void ShowGameOverUI() {
|
2018-04-23 13:35:56 +02:00
|
|
|
|
ShowRestartUI(false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void ShowWinUI() {
|
|
|
|
|
ShowRestartUI(true);
|
|
|
|
|
}
|
2018-04-22 00:22:56 +02:00
|
|
|
|
|
2018-04-23 13:35:56 +02:00
|
|
|
|
void ShowRestartUI(bool won) {
|
|
|
|
|
string headerText = won ? "You won!" : "Game Over";
|
|
|
|
|
if (restartUIPanel != null) {
|
|
|
|
|
restartUIPanel.SetActive(true);
|
2018-04-23 14:59:34 +02:00
|
|
|
|
restartUIPanel.GetComponentInChildren<Text>().text = headerText;
|
2018-04-22 22:35:20 +02:00
|
|
|
|
} else {
|
2018-04-23 13:35:56 +02:00
|
|
|
|
Debug.Log("No restart panel assigned");
|
2018-04-22 00:22:56 +02:00
|
|
|
|
}
|
2018-04-22 05:57:26 +02:00
|
|
|
|
}
|
2018-04-22 15:59:14 +02:00
|
|
|
|
|
2018-04-23 13:17:59 +02:00
|
|
|
|
public void InitHealthController(Player ply) {
|
2018-04-22 15:59:14 +02:00
|
|
|
|
healthcontroller.SetPlayer(ply);
|
|
|
|
|
}
|
2018-04-22 20:10:05 +02:00
|
|
|
|
|
2018-04-23 21:14:04 +02:00
|
|
|
|
public void InitBrakeController(Player ply) {
|
|
|
|
|
brakeBarController.SetPlayer(ply);
|
|
|
|
|
}
|
|
|
|
|
|
2018-04-22 20:10:05 +02:00
|
|
|
|
public NotificationManager GetNotificationManager() {
|
|
|
|
|
return notifications;
|
|
|
|
|
}
|
2018-04-24 02:15:58 +02:00
|
|
|
|
|
|
|
|
|
public void showPauseUI(bool show) {
|
|
|
|
|
if (pausedUIPanel != null) {
|
|
|
|
|
pausedUIPanel.SetActive(show);
|
|
|
|
|
} else {
|
|
|
|
|
Debug.Log("Paused UI not assigned");
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-04-21 12:22:17 +02:00
|
|
|
|
}
|