b6804e2986
the console should finally be message free! except for the unity memory leak lol but that one's not on us
223 lines
5.5 KiB
C#
223 lines
5.5 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.SceneManagement;
|
|
using UnityEngine.UI;
|
|
|
|
public enum UnlockedItems
|
|
{
|
|
None,
|
|
Trumpet,
|
|
Tambourine,
|
|
Clarinet,
|
|
Cymbal,
|
|
}
|
|
|
|
public class StateController : MonoBehaviour
|
|
{
|
|
|
|
// Singleton class
|
|
public static StateController Instance = null;
|
|
|
|
[Header("Respawning")]
|
|
[SerializeField] GameObject player;
|
|
public GameObject spawnPoint;
|
|
[SerializeField] private GameObject deathCanvas;
|
|
|
|
[Header("Pause Menu")]
|
|
public bool isPaused = false;
|
|
public GameObject pauseMenuCanvas;
|
|
|
|
[Header("Debug")]
|
|
public bool inDebugMode;
|
|
public GameObject debugCanvas;
|
|
|
|
[Header("Enemies")]
|
|
GameObject[] enemiesInScene;
|
|
|
|
[Header("Level Progression")]
|
|
GameObject victoryCanvas;
|
|
|
|
[Header("Unlocked Items")]
|
|
public UnlockedItems itemProgression = UnlockedItems.None;
|
|
|
|
void Awake()
|
|
{
|
|
if (Instance == null)
|
|
{
|
|
Instance = this;
|
|
} else {
|
|
Destroy(this.gameObject);
|
|
return;
|
|
}
|
|
DontDestroyOnLoad(this.gameObject);
|
|
SceneManager.sceneLoaded += OnSceneLoaded;
|
|
}
|
|
|
|
void Start() {
|
|
if (this.inDebugMode)
|
|
{
|
|
debugCanvas = GameObject.Find("DebugCanvas");
|
|
debugCanvas.SetActive(false);
|
|
}
|
|
}
|
|
|
|
public bool HasTrumpet()
|
|
{
|
|
return this.itemProgression >= UnlockedItems.Trumpet;
|
|
}
|
|
|
|
|
|
public bool HasTambourine()
|
|
{
|
|
return this.itemProgression >= UnlockedItems.Tambourine;
|
|
}
|
|
|
|
|
|
public bool HasClarinet()
|
|
{
|
|
return this.itemProgression >= UnlockedItems.Clarinet;
|
|
}
|
|
|
|
public bool HasCymbal()
|
|
{
|
|
return this.itemProgression >= UnlockedItems.Cymbal;
|
|
}
|
|
|
|
void OnSceneLoaded(Scene scene, LoadSceneMode mode)
|
|
{
|
|
|
|
#region FIND OBJECTS
|
|
deathCanvas = GameObject.Find("DeathUICanvas");
|
|
if (deathCanvas != null)
|
|
{
|
|
Button respawnButton = GameObject.Find("RespawnButton").GetComponent<Button>();
|
|
respawnButton.onClick.AddListener(RespawnPlayer);
|
|
deathCanvas.SetActive(false);
|
|
}
|
|
|
|
pauseMenuCanvas = GameObject.Find("PauseMenuCanvas");
|
|
if (pauseMenuCanvas != null)
|
|
{
|
|
Button resumeButton = GameObject.Find("ResumeButton").GetComponent<Button>();
|
|
resumeButton.onClick.AddListener(Unpause);
|
|
Button quitButton = GameObject.Find("QuitButton").GetComponent<Button>();
|
|
quitButton.onClick.AddListener(SceneController.Instance.BackToMainMenu);
|
|
TogglePauseMenu(false);
|
|
}
|
|
|
|
victoryCanvas = GameObject.Find("VictoryCanvas");
|
|
if (victoryCanvas != null)
|
|
{
|
|
Button continueButton = GameObject.Find("ContinueButton").GetComponent<Button>();
|
|
continueButton.onClick.AddListener(ContinueToNextLevel);
|
|
victoryCanvas.SetActive(false);
|
|
}
|
|
|
|
// keep track of all enemies
|
|
enemiesInScene = GameObject.FindGameObjectsWithTag("Enemy");
|
|
|
|
if (isPaused)
|
|
{
|
|
Unpause();
|
|
}
|
|
#endregion
|
|
|
|
#region UNLOCK ITEMS
|
|
switch (SceneManager.GetActiveScene().name)
|
|
{
|
|
case "GrenouilleVillage":
|
|
this.itemProgression = UnlockedItems.None;
|
|
break;
|
|
case "Brasslands":
|
|
this.itemProgression = UnlockedItems.Trumpet;
|
|
break;
|
|
case "GrappleScene":
|
|
this.itemProgression = UnlockedItems.Tambourine;
|
|
break;
|
|
case "ClarinetScene":
|
|
this.itemProgression = UnlockedItems.Clarinet;
|
|
break;
|
|
case "MushroomForest":
|
|
this.itemProgression = UnlockedItems.Cymbal;
|
|
break;
|
|
};
|
|
#endregion
|
|
}
|
|
|
|
void OnToggleDebugMenu()
|
|
{
|
|
if (inDebugMode)
|
|
{
|
|
debugCanvas.SetActive(!this.debugCanvas.activeSelf);
|
|
}
|
|
}
|
|
|
|
void OnPause()
|
|
{
|
|
if (pauseMenuCanvas != null)
|
|
{
|
|
if (!isPaused)
|
|
{
|
|
Time.timeScale = 0;
|
|
TogglePauseMenu(true);
|
|
}
|
|
else
|
|
{
|
|
Time.timeScale = 1;
|
|
TogglePauseMenu(false);
|
|
}
|
|
isPaused = !isPaused;
|
|
}
|
|
}
|
|
|
|
public void Unpause()
|
|
{
|
|
Time.timeScale = 1;
|
|
TogglePauseMenu(false);
|
|
isPaused = !isPaused;
|
|
}
|
|
|
|
void TogglePauseMenu(bool showPauseMenu)
|
|
{
|
|
if (pauseMenuCanvas != null) {
|
|
pauseMenuCanvas.SetActive(showPauseMenu);
|
|
}
|
|
}
|
|
|
|
public void RespawnPlayer()
|
|
{
|
|
Destroy(GameObject.FindGameObjectWithTag("Player"));
|
|
SetDeathCanvasActive(false);
|
|
GameObject.Find("Main Camera").GetComponent<CameraMovement>().FindPlayer();
|
|
RespawnEnemies();
|
|
Instantiate(player, spawnPoint.transform.position, player.transform.rotation);
|
|
}
|
|
|
|
public void RespawnEnemies()
|
|
{
|
|
foreach (GameObject enemy in enemiesInScene)
|
|
{
|
|
if (enemy.GetComponent<EnemyPatrol>().isPlayingDefeatAnimation) {
|
|
enemy.SetActive(false);
|
|
}
|
|
enemy.SetActive(true);
|
|
}
|
|
}
|
|
|
|
public void SetDeathCanvasActive(bool activeState)
|
|
{
|
|
deathCanvas.SetActive(activeState);
|
|
}
|
|
|
|
public void ShowVictoryCanvas()
|
|
{
|
|
victoryCanvas.SetActive(true);
|
|
}
|
|
|
|
public void ContinueToNextLevel()
|
|
{
|
|
SceneController.Instance.NextScene();
|
|
}
|
|
}
|