2025-02-10 21:33:49 +08:00
|
|
|
/*
|
2025-02-04 09:08:06 +08:00
|
|
|
Author: Reza
|
|
|
|
Date: 3/2/25
|
2025-02-08 22:11:47 +08:00
|
|
|
Description: To keep track of tasks, which level the player is at, and game mechanics
|
2025-02-04 09:08:06 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
using System.Collections;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using UnityEngine;
|
2025-02-10 12:20:10 +08:00
|
|
|
using TMPro;
|
2025-02-04 09:08:06 +08:00
|
|
|
|
|
|
|
public class GameManager : MonoBehaviour
|
|
|
|
{
|
2025-02-08 22:11:47 +08:00
|
|
|
/// <summary>
|
2025-02-10 21:33:49 +08:00
|
|
|
/// Define instance field for accessing the singleton elsewhere
|
2025-02-08 22:11:47 +08:00
|
|
|
/// </summary>
|
|
|
|
public static GameManager Instance;
|
2025-02-10 12:20:10 +08:00
|
|
|
|
2025-02-11 15:01:17 +08:00
|
|
|
// Defines UI references
|
|
|
|
[Header("UI References")]
|
|
|
|
public GameObject storyPanelUI;
|
|
|
|
public TMP_Text storyText;
|
2025-02-10 21:33:49 +08:00
|
|
|
|
|
|
|
// Trackable Task Completions
|
2025-02-10 12:20:10 +08:00
|
|
|
private bool bedroomCleaned = false;
|
|
|
|
private bool teethBrushed = false;
|
|
|
|
private bool floorSweeped = false;
|
2025-02-12 11:28:28 +08:00
|
|
|
|
|
|
|
// Queue for managing messages
|
|
|
|
private Queue<string> messageQueue = new Queue<string>();
|
|
|
|
private bool isMessageActive = false;
|
2025-02-08 22:11:47 +08:00
|
|
|
|
|
|
|
/// <summary>
|
2025-02-10 21:33:49 +08:00
|
|
|
/// Checks if tasks are completed
|
|
|
|
/// </summary>
|
|
|
|
public bool IsBedroomCleaned() { return bedroomCleaned; }
|
|
|
|
public bool IsTeethBrushed() { return teethBrushed; }
|
|
|
|
public bool IsFloorSweeped() { return floorSweeped; }
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Enforces singleton behaviour; sets doesn't destroy on load and checks for multiple instances
|
2025-02-08 22:11:47 +08:00
|
|
|
/// </summary>
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
2025-02-04 09:08:06 +08:00
|
|
|
|
|
|
|
// Update is called once per frame
|
|
|
|
void Update()
|
|
|
|
{
|
2025-02-12 11:28:28 +08:00
|
|
|
// Continuously check and display queued messages
|
|
|
|
if (!isMessageActive && messageQueue.Count > 0)
|
|
|
|
{
|
|
|
|
string nextMessage = messageQueue.Dequeue();
|
|
|
|
StartCoroutine(DisplayMessage(nextMessage));
|
|
|
|
}
|
2025-02-04 09:08:06 +08:00
|
|
|
}
|
2025-02-12 11:28:28 +08:00
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Queues a message to be displayed
|
|
|
|
/// </summary>
|
|
|
|
public void QueueMessage(string message)
|
|
|
|
{
|
|
|
|
messageQueue.Enqueue(message);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Displays a message and waits for it to disappear
|
|
|
|
/// </summary>
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2025-02-10 21:33:49 +08:00
|
|
|
// 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);
|
|
|
|
}
|
2025-02-11 15:01:17 +08:00
|
|
|
|
|
|
|
public void AreTasksDone()
|
|
|
|
{
|
|
|
|
if (bedroomCleaned && teethBrushed && floorSweeped)
|
|
|
|
{
|
2025-02-12 11:28:28 +08:00
|
|
|
QueueMessage("I think I did everything... I think I can leave for school now");
|
2025-02-11 15:01:17 +08:00
|
|
|
}
|
|
|
|
}
|
2025-02-10 21:33:49 +08:00
|
|
|
|
|
|
|
// Tracks if bedroom is cleaned or not
|
2025-02-09 20:47:12 +08:00
|
|
|
public void BedroomTaskComplete()
|
|
|
|
{
|
|
|
|
bedroomCleaned = true;
|
2025-02-11 15:01:17 +08:00
|
|
|
AreTasksDone();
|
2025-02-09 20:47:12 +08:00
|
|
|
}
|
2025-02-10 00:56:32 +08:00
|
|
|
|
2025-02-10 21:33:49 +08:00
|
|
|
// Tracks if teeth is brushed or not
|
2025-02-10 00:56:32 +08:00
|
|
|
public void BrushTeethTaskComplete()
|
|
|
|
{
|
|
|
|
teethBrushed = true;
|
2025-02-11 15:01:17 +08:00
|
|
|
AreTasksDone();
|
2025-02-10 00:56:32 +08:00
|
|
|
}
|
2025-02-10 21:33:49 +08:00
|
|
|
|
|
|
|
// Tracks if floor is sweeped or not
|
|
|
|
public void FloorSweepedTaskComplete()
|
|
|
|
{
|
|
|
|
floorSweeped = true;
|
2025-02-11 15:01:17 +08:00
|
|
|
AreTasksDone();
|
|
|
|
}
|
2025-02-04 09:08:06 +08:00
|
|
|
}
|