change: Switched the state controller and scene controller to a singleton class

This doesnt' change any of the logic, but simplifies a lot of the main
game loop code.

Many things still rely on the singleton class, but shouldn't so this
will be fixed in a later commit
This commit is contained in:
Nicholas Novak
2023-05-04 02:19:51 -07:00
parent afbcb920ac
commit 5a7ce8fb2b
8 changed files with 301 additions and 211 deletions

View File

@@ -14,64 +14,50 @@ public class GameUIController : MonoBehaviour
[HideInInspector] public GameObject tambourineUI;
[HideInInspector] public GameObject clarinetUI;
[Header("Other Objects")]
private StateController stateController;
void Start()
{
this.trumpetUI = trumpetBackground.transform.GetChild(0).gameObject;
this.tambourineUI = tambourineBackground.transform.GetChild(0).gameObject;
this.clarinetUI = clarinetBackground.transform.GetChild(0).gameObject;
void Start() {
stateController = GameObject.FindGameObjectWithTag("StateController").GetComponent<StateController>();
if (stateController == null) {
print("state controller not found");
} else {
print("yeehaw");
}
trumpetUI = trumpetBackground.transform.GetChild(0).gameObject;
tambourineUI = tambourineBackground.transform.GetChild(0).gameObject;
clarinetUI = clarinetBackground.transform.GetChild(0).gameObject;
if (!stateController.unlockedTrumpet) {
trumpetBackground.SetActive(false);
}
if (!stateController.unlockedTambourine) {
tambourineBackground.SetActive(false);
}
if (!stateController.unlockedClarinet) {
clarinetBackground.SetActive(false);
}
// TODO: This can be probably be combined with the update methods
this.trumpetBackground.SetActive(StateController.Instance.HasTrumpet());
this.tambourineBackground.SetActive(StateController.Instance.HasTambourine());
this.clarinetBackground.SetActive(StateController.Instance.HasClarinet());
}
public void ToggleTrumpet(bool toggleState) {
public void ToggleTrumpet(bool toggleState)
{
bool curEnabled = trumpetUI.GetComponent<Image>().enabled;
if (curEnabled != toggleState) {
if (curEnabled != toggleState)
{
trumpetUI.GetComponent<Image>().enabled = toggleState;
}
}
public void ToggleTambourine(bool toggleState) {
public void ToggleTambourine(bool toggleState)
{
bool curEnabled = tambourineUI.GetComponent<Image>().enabled;
if (curEnabled != toggleState) {
if (curEnabled != toggleState)
{
tambourineUI.GetComponent<Image>().enabled = toggleState;
}
}
public void ToggleClarinet(bool toggleState) {
public void ToggleClarinet(bool toggleState)
{
bool curEnabled = clarinetUI.GetComponent<Image>().enabled;
if (curEnabled != toggleState) {
if (curEnabled != toggleState)
{
clarinetUI.GetComponent<Image>().enabled = toggleState;
}
}
public void ResetInstrumentUI() {
if (stateController == null) {
print("state controller null");
}
if (stateController.unlockedTrumpet) {
ToggleTrumpet(true);
}
if (stateController.unlockedTambourine) {
ToggleTambourine(true);
}
if (stateController.unlockedClarinet) {
ToggleClarinet(true);
}
public void UpdateInstrumentUI()
{
this.ToggleTrumpet(StateController.Instance.HasTrumpet());
this.ToggleTambourine(StateController.Instance.HasTambourine());
this.ToggleClarinet(StateController.Instance.HasClarinet());
}
}