2025-03-06 01:27:42 -05:00
|
|
|
using System.Linq;
|
2025-04-16 19:57:54 -04:00
|
|
|
using UnityEngine; using Game; using Music; using Player;
|
2025-01-09 11:07:20 -05:00
|
|
|
using UnityEngine.InputSystem;
|
|
|
|
|
using UnityEngine.SceneManagement;
|
2025-01-09 12:30:22 -05:00
|
|
|
using UnityEngine.UI;
|
2025-03-07 23:32:42 -05:00
|
|
|
using UnityEngine.Events;
|
2025-04-12 17:28:51 -04:00
|
|
|
using System.Collections;
|
2025-01-09 11:07:20 -05:00
|
|
|
|
2025-04-16 19:57:54 -04:00
|
|
|
namespace Game{
|
2025-01-09 11:07:20 -05:00
|
|
|
public class HubManager : MonoBehaviour
|
|
|
|
|
{
|
2025-02-19 20:11:57 -05:00
|
|
|
public static HubManager Instance;
|
2025-02-09 17:18:51 -05:00
|
|
|
public GameObject hubCamera;
|
2025-01-09 12:30:22 -05:00
|
|
|
public GameObject gameButtonsParent;
|
|
|
|
|
|
2025-02-09 17:18:51 -05:00
|
|
|
private void Start()
|
|
|
|
|
{
|
2025-02-19 20:11:57 -05:00
|
|
|
if (Instance == null)
|
|
|
|
|
{
|
|
|
|
|
Instance = this;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Destroy(this.gameObject);
|
|
|
|
|
}
|
2025-04-18 14:27:08 -04:00
|
|
|
if (hubCamera.GetComponent<AudioListener>() == null)
|
|
|
|
|
{
|
|
|
|
|
hubCamera.AddComponent<AudioListener>();
|
|
|
|
|
}
|
2025-02-09 17:18:51 -05:00
|
|
|
hubCamera.SetActive(true);
|
2025-03-07 23:32:42 -05:00
|
|
|
MusicManager.Instance.StartPlaylist();
|
2025-04-18 14:27:08 -04:00
|
|
|
print("Game started");
|
|
|
|
|
}
|
2025-02-09 17:18:51 -05:00
|
|
|
|
2025-01-09 11:07:20 -05:00
|
|
|
public void LoadScene(string sceneName)
|
|
|
|
|
{
|
|
|
|
|
UnloadGameScene();
|
2025-02-16 16:47:45 -05:00
|
|
|
hubCamera.SetActive(false);
|
2025-01-09 11:07:20 -05:00
|
|
|
SceneManager.LoadScene(sceneName, LoadSceneMode.Additive);
|
2025-04-18 14:27:08 -04:00
|
|
|
var activeCamera = Camera.main;
|
|
|
|
|
if (activeCamera != null && activeCamera.GetComponent<AudioListener>() == null)
|
|
|
|
|
{
|
|
|
|
|
activeCamera.gameObject.AddComponent<AudioListener>();
|
|
|
|
|
}
|
2025-03-07 23:32:42 -05:00
|
|
|
MusicManager.Instance.StartPlaylist();
|
2025-04-18 14:27:08 -04:00
|
|
|
print("Loading scene: " + sceneName);
|
2025-01-09 11:07:20 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void UnloadGameScene()
|
|
|
|
|
{
|
2025-02-16 16:47:45 -05:00
|
|
|
hubCamera.SetActive(true);
|
2025-01-09 11:07:20 -05:00
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
SceneManager.UnloadSceneAsync(SceneManager.GetSceneAt(1));
|
|
|
|
|
}
|
2025-04-18 14:27:08 -04:00
|
|
|
catch {}
|
2025-01-09 12:30:22 -05:00
|
|
|
ChangeGameButtonsInteractability(false);
|
2025-01-09 11:07:20 -05:00
|
|
|
}
|
|
|
|
|
|
2025-04-18 02:50:50 -04:00
|
|
|
private void Update()
|
2025-01-09 11:07:20 -05:00
|
|
|
{
|
|
|
|
|
if (InputSystem.GetDevice<Keyboard>().escapeKey.wasPressedThisFrame)
|
|
|
|
|
{
|
|
|
|
|
UnloadGameScene();
|
2025-01-09 12:30:22 -05:00
|
|
|
ChangeGameButtonsInteractability(true);
|
2025-04-18 02:50:50 -04:00
|
|
|
if (GameManager.players != null)
|
2025-03-05 13:31:40 -05:00
|
|
|
{
|
2025-04-18 02:50:50 -04:00
|
|
|
foreach (GameObject player in GameManager.players.ToList())
|
|
|
|
|
{
|
|
|
|
|
GameManager.players.Remove(player);
|
|
|
|
|
if (player != null)
|
|
|
|
|
{
|
|
|
|
|
Destroy(player);
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-03-05 13:31:40 -05:00
|
|
|
}
|
2025-04-18 02:50:50 -04:00
|
|
|
if (MusicManager.Instance != null)
|
2025-03-07 23:32:42 -05:00
|
|
|
{
|
2025-04-18 02:50:50 -04:00
|
|
|
MusicManager.Instance.StartPlaylist("Title Screen");
|
|
|
|
|
}
|
|
|
|
|
var cameras = FindObjectsByType<Camera>(FindObjectsSortMode.None);
|
|
|
|
|
if (cameras != null)
|
|
|
|
|
{
|
|
|
|
|
foreach (Camera camera in cameras)
|
|
|
|
|
{
|
|
|
|
|
camera.enabled = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
GameManager.players?.Clear();
|
|
|
|
|
GameManager.playerColors?.Clear();
|
|
|
|
|
if (GameManager.Instance != null)
|
|
|
|
|
{
|
|
|
|
|
GameManager.Instance.gameOver = false;
|
2025-03-07 23:32:42 -05:00
|
|
|
}
|
|
|
|
|
SceneManager.LoadScene("Title Screen");
|
2025-04-18 02:50:50 -04:00
|
|
|
|
2025-01-09 12:30:22 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void ChangeGameButtonsInteractability(bool interactable)
|
|
|
|
|
{
|
2025-03-29 15:18:27 -04:00
|
|
|
gameButtonsParent.transform.parent.gameObject.SetActive(interactable);
|
2025-01-09 12:30:22 -05:00
|
|
|
foreach (Transform button in gameButtonsParent.transform)
|
|
|
|
|
{
|
|
|
|
|
button.GetComponent<Button>().interactable = interactable;
|
2025-01-09 11:07:20 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-04-16 19:57:54 -04:00
|
|
|
}
|