/* Author: Reza Date: 3/2/25 Description: To keep track of tasks, which level the player is at, and game mechanics */ using System.Collections; using System.Collections.Generic; using UnityEngine; using TMPro; public class GameManager : MonoBehaviour { /// /// Define instance field for accessing the singleton elsewhere /// public static GameManager Instance; // Defines UI references [Header("UI References")] public GameObject storyPanelUI; public TMP_Text storyText; // Trackable Task Completions private bool bedroomCleaned = false; private bool teethBrushed = false; private bool floorSweeped = false; // Queue for managing messages private Queue messageQueue = new Queue(); private bool isMessageActive = false; /// /// Checks if tasks are completed /// public bool IsBedroomCleaned() { return bedroomCleaned; } public bool IsTeethBrushed() { return teethBrushed; } public bool IsFloorSweeped() { return floorSweeped; } /// /// Enforces singleton behaviour; sets doesn't destroy on load and checks for multiple instances /// private void Awake() { // check if instance hasn't been set yet if (Instance == null) { Debug.Log("awake as singleton instance, setting self as the forever-alive instance"); Instance = this; DontDestroyOnLoad(gameObject); } // check if instance is already set and it's not this instance else if (Instance != null && Instance != this) { Debug.Log("awake as non-singleton instance, destroying self"); Destroy(gameObject); } } // Update is called once per frame void Update() { // Continuously check and display queued messages if (!isMessageActive && messageQueue.Count > 0) { string nextMessage = messageQueue.Dequeue(); StartCoroutine(DisplayMessage(nextMessage)); } } /// /// Queues a message to be displayed /// public void QueueMessage(string message) { messageQueue.Enqueue(message); } /// /// Displays a message and waits for it to disappear /// private IEnumerator DisplayMessage(string message) { isMessageActive = true; storyPanelUI.SetActive(true); storyText.text = message; yield return new WaitForSeconds(7f); // Wait for 7 seconds before hiding storyPanelUI.SetActive(false); isMessageActive = false; } // Logs player's choices before leaving the house (for future Firebase tracking) public void LogPlayerChoices() { Debug.Log("Player is trying to leave the house. Task Completion Status:"); Debug.Log("Bedroom Cleaned: " + bedroomCleaned); Debug.Log("Teeth Brushed: " + teethBrushed); Debug.Log("Floor Sweeped: " + floorSweeped); } public void AreTasksDone() { if (bedroomCleaned && teethBrushed && floorSweeped) { QueueMessage("I think I did everything... I think I can leave for school now"); } } // Tracks if bedroom is cleaned or not public void BedroomTaskComplete() { bedroomCleaned = true; AreTasksDone(); } // Tracks if teeth is brushed or not public void BrushTeethTaskComplete() { teethBrushed = true; AreTasksDone(); } // Tracks if floor is sweeped or not public void FloorSweepedTaskComplete() { floorSweeped = true; AreTasksDone(); } }