game(scripts): standardise GameManager
This commit is contained in:
parent
6d3005d9d7
commit
587e6a1c6e
1 changed files with 48 additions and 56 deletions
|
@ -1,13 +1,13 @@
|
||||||
/*
|
/*
|
||||||
Author: Reza and Wai Lam
|
* Author: Reza and Wai Lam
|
||||||
Date: 3/2/25
|
* Date: 3/2/25
|
||||||
Description: To keep track of tasks, which level the player is at, and game mechanics
|
* Description: To keep track of tasks, which level the player is at, and game mechanics
|
||||||
*/
|
*/
|
||||||
|
|
||||||
using System.Collections;
|
using System.Collections;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using UnityEngine;
|
|
||||||
using TMPro;
|
using TMPro;
|
||||||
|
using UnityEngine;
|
||||||
using UnityEngine.SceneManagement;
|
using UnityEngine.SceneManagement;
|
||||||
|
|
||||||
public class GameManager : MonoBehaviour
|
public class GameManager : MonoBehaviour
|
||||||
|
@ -17,51 +17,28 @@ public class GameManager : MonoBehaviour
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static GameManager Instance;
|
public static GameManager Instance;
|
||||||
|
|
||||||
// current day, publicly readable, privately settable
|
|
||||||
|
|
||||||
// for public access, setting is a no-op
|
|
||||||
public int currentDay { get; private set; } = 1;
|
|
||||||
|
|
||||||
// Tracks GoToSchool task status
|
|
||||||
private bool goToSchool = false;
|
|
||||||
private bool bedroomCleaned = false;
|
|
||||||
private bool teethBrushed = false;
|
|
||||||
private bool floorSweeped = false;
|
|
||||||
|
|
||||||
private string lastSceneName;
|
|
||||||
|
|
||||||
private bool hasIncrementedToday = false;
|
|
||||||
|
|
||||||
// Defines UI references
|
// Defines UI references
|
||||||
[Header("UI References")] public GameObject storyPanelUI;
|
[Header("UI References")] public GameObject storyPanelUI;
|
||||||
public TMP_Text storyText;
|
public TMP_Text storyText;
|
||||||
|
|
||||||
// Queue for managing messages
|
// Queue for managing messages
|
||||||
private Queue<string> messageQueue = new Queue<string>();
|
private readonly Queue<string> messageQueue = new();
|
||||||
private bool isMessageActive = false;
|
private bool bedroomCleaned;
|
||||||
|
private bool floorSweeped;
|
||||||
|
|
||||||
/// <summary>
|
// Tracks GoToSchool task status
|
||||||
/// Checks if tasks are completed
|
private bool goToSchool;
|
||||||
/// </summary>
|
|
||||||
public bool IsBedroomCleaned()
|
|
||||||
{
|
|
||||||
return bedroomCleaned;
|
|
||||||
}
|
|
||||||
|
|
||||||
public bool IsTeethBrushed()
|
private bool hasIncrementedToday;
|
||||||
{
|
private bool isMessageActive;
|
||||||
return teethBrushed;
|
|
||||||
}
|
|
||||||
|
|
||||||
public bool IsFloorSweeped()
|
private string lastSceneName;
|
||||||
{
|
private bool teethBrushed;
|
||||||
return floorSweeped;
|
|
||||||
}
|
|
||||||
|
|
||||||
public bool IsGoToSchool()
|
// current day, publicly readable, privately settable
|
||||||
{
|
|
||||||
return goToSchool;
|
// for public access, setting is a no-op
|
||||||
}
|
public int currentDay { get; private set; } = 1;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Enforces singleton behavior; sets doesn't destroy on load and checks for multiple instances
|
/// Enforces singleton behavior; sets doesn't destroy on load and checks for multiple instances
|
||||||
|
@ -88,30 +65,47 @@ public class GameManager : MonoBehaviour
|
||||||
currentDay = 1;
|
currentDay = 1;
|
||||||
|
|
||||||
// Try to find UI elements if not set
|
// Try to find UI elements if not set
|
||||||
if (storyPanelUI == null)
|
if (storyPanelUI == null) storyPanelUI = GameObject.Find("StoryPanelUI");
|
||||||
{
|
|
||||||
storyPanelUI = GameObject.Find("StoryPanelUI");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (storyText == null)
|
if (storyText == null) storyText = GameObject.Find("StoryText").GetComponent<TMP_Text>();
|
||||||
{
|
|
||||||
storyText = GameObject.Find("StoryText").GetComponent<TMP_Text>();
|
|
||||||
}
|
|
||||||
|
|
||||||
SceneManager.sceneLoaded += OnSceneLoaded;
|
SceneManager.sceneLoaded += OnSceneLoaded;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update is called once per frame
|
// Update is called once per frame
|
||||||
void Update()
|
private void Update()
|
||||||
{
|
{
|
||||||
// Continuously check and display queued messages
|
// Continuously check and display queued messages
|
||||||
if (!isMessageActive && messageQueue.Count > 0)
|
if (!isMessageActive && messageQueue.Count > 0)
|
||||||
{
|
{
|
||||||
string nextMessage = messageQueue.Dequeue();
|
var nextMessage = messageQueue.Dequeue();
|
||||||
StartCoroutine(DisplayMessage(nextMessage));
|
StartCoroutine(DisplayMessage(nextMessage));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Checks if tasks are completed
|
||||||
|
/// </summary>
|
||||||
|
public bool IsBedroomCleaned()
|
||||||
|
{
|
||||||
|
return bedroomCleaned;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool IsTeethBrushed()
|
||||||
|
{
|
||||||
|
return teethBrushed;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool IsFloorSweeped()
|
||||||
|
{
|
||||||
|
return floorSweeped;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool IsGoToSchool()
|
||||||
|
{
|
||||||
|
return goToSchool;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Queues a message to be displayed
|
/// Queues a message to be displayed
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -147,11 +141,9 @@ public class GameManager : MonoBehaviour
|
||||||
public void AreTasksDone()
|
public void AreTasksDone()
|
||||||
{
|
{
|
||||||
if (bedroomCleaned && teethBrushed && floorSweeped)
|
if (bedroomCleaned && teethBrushed && floorSweeped)
|
||||||
{
|
|
||||||
QueueMessage("I think I did everything... I think I can leave for school now");
|
QueueMessage("I think I did everything... I think I can leave for school now");
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// mark : u can track whether they want to do their tasks, some people may be unmoticvated to
|
// mark : u can track whether they want to do their tasks, some people may be unmoticvated to
|
||||||
// do the tasks in game, then we can ask them irl why they didnt do the task
|
// do the tasks in game, then we can ask them irl why they didnt do the task
|
||||||
|
|
||||||
|
@ -186,13 +178,13 @@ public class GameManager : MonoBehaviour
|
||||||
{
|
{
|
||||||
if (hasIncrementedToday) return; // Prevents multiple increments
|
if (hasIncrementedToday) return; // Prevents multiple increments
|
||||||
hasIncrementedToday = true;
|
hasIncrementedToday = true;
|
||||||
|
|
||||||
currentDay++;
|
currentDay++;
|
||||||
Debug.Log("Day incremented to: " + currentDay);
|
Debug.Log("Day incremented to: " + currentDay);
|
||||||
if (currentDay > 3) LoadCallingScene();
|
if (currentDay > 3) LoadCallingScene();
|
||||||
}
|
}
|
||||||
|
|
||||||
void OnSceneLoaded(Scene scene, LoadSceneMode mode)
|
private void OnSceneLoaded(Scene scene, LoadSceneMode mode)
|
||||||
{
|
{
|
||||||
hasIncrementedToday = false; // Allows the day to be incremented again in the next transition
|
hasIncrementedToday = false; // Allows the day to be incremented again in the next transition
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue