add time manager and day/night cycle
This commit is contained in:
@@ -10,6 +10,7 @@ public class GameManager : MonoBehaviour
|
||||
{
|
||||
public static GameManager Instance { get; private set; }
|
||||
public DialogueManager DialogueManager { get; private set; }
|
||||
public TimeManager TimeManager { get; private set; }
|
||||
public Inventory Inventory { get; private set; }
|
||||
public Storybools Storybools { get; private set; }
|
||||
|
||||
@@ -50,6 +51,7 @@ private void ReloadReferences()
|
||||
Instance.DialogueManager.ReloadReferences();
|
||||
|
||||
Instance.Inventory = GetComponent<Inventory>();
|
||||
Instance.TimeManager = GetComponent<TimeManager>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -12,6 +12,7 @@ public struct SaveData
|
||||
public QuestSaveData QuestData;
|
||||
public StoryboolSaveData StoryboolData;
|
||||
public InventorySaveData InventorySaveData;
|
||||
public TimeSaveData TimeSaveData;
|
||||
}
|
||||
|
||||
public static string SaveFileName()
|
||||
@@ -43,6 +44,7 @@ private static void HandleSaveData()
|
||||
{
|
||||
GameManager.Instance.SaveStoryBools(ref _saveData.StoryboolData);
|
||||
GameManager.Instance.Inventory.SaveInventory(ref _saveData.InventorySaveData);
|
||||
GameManager.Instance.TimeManager.SaveTime(ref _saveData.TimeSaveData);
|
||||
QuestRegistry.Instance.SaveQuestData(ref _saveData.QuestData);
|
||||
}
|
||||
|
||||
@@ -81,6 +83,7 @@ public static void HandleLoadData()
|
||||
{
|
||||
GameManager.Instance.LoadStoryBools(_saveData.StoryboolData);
|
||||
GameManager.Instance.Inventory.LoadInventory(_saveData.InventorySaveData);
|
||||
GameManager.Instance.TimeManager.LoadTime(_saveData.TimeSaveData);
|
||||
QuestRegistry.Instance.LoadQuestData(_saveData.QuestData);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,105 @@
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
|
||||
public class TimeManager : MonoBehaviour
|
||||
{
|
||||
private const int HOURS_PER_DAY = 24;
|
||||
private const int MINUTES_PER_HOUR = 60;
|
||||
public const int SECONDS_PER_MINUTE = 2;
|
||||
|
||||
private int currentHour = 12;
|
||||
private int currentMinute = 0;
|
||||
private float currentSecond = 0;
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
StepTime();
|
||||
}
|
||||
|
||||
private void StepTime()
|
||||
{
|
||||
currentSecond += Time.deltaTime;
|
||||
|
||||
if (currentSecond > SECONDS_PER_MINUTE)
|
||||
{
|
||||
currentSecond = 0;
|
||||
currentMinute += 1;
|
||||
}
|
||||
|
||||
if (currentMinute > MINUTES_PER_HOUR - 1)
|
||||
{
|
||||
currentMinute = 0;
|
||||
currentHour += 1;
|
||||
}
|
||||
|
||||
if (currentHour > (HOURS_PER_DAY - 1))
|
||||
{
|
||||
currentHour = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get the current second within the current minute
|
||||
/// </summary>
|
||||
/// <returns>Current second within the current minute</returns>
|
||||
public float GetCurrentSecond()
|
||||
{
|
||||
return currentSecond;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get the current minute within the current hour
|
||||
/// </summary>
|
||||
/// <returns>Current minute within the current hour</returns>
|
||||
public int GetCurrentMinute()
|
||||
{
|
||||
return currentMinute;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get the current hour within the current day
|
||||
/// </summary>
|
||||
/// <returns>Current hour within the current day</returns>
|
||||
public int GetCurrentHour()
|
||||
{
|
||||
return currentHour;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a formatted time string
|
||||
/// </summary>
|
||||
/// <returns>Returns a formatted string with the hour, minute, and second</returns>
|
||||
public string GetTimeString()
|
||||
{
|
||||
string formattedHour = currentHour.ToString("00");
|
||||
string formattedMinute = currentMinute.ToString("00");
|
||||
string formattedSecond = currentSecond.ToString("00.00");
|
||||
|
||||
return $"{formattedHour}:{formattedMinute}:{formattedSecond}";
|
||||
}
|
||||
|
||||
#region Time Save/Load
|
||||
public void SaveTime(ref TimeSaveData data)
|
||||
{
|
||||
data.hour = currentHour;
|
||||
data.minute = currentMinute;
|
||||
data.second = currentSecond;
|
||||
}
|
||||
|
||||
public void LoadTime(TimeSaveData data)
|
||||
{
|
||||
currentHour = data.hour;
|
||||
currentMinute = data.minute;
|
||||
currentSecond = data.second;
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
|
||||
[System.Serializable]
|
||||
public struct TimeSaveData
|
||||
{
|
||||
public int hour;
|
||||
public int minute;
|
||||
public float second;
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1b892c02d92dd70419f61cf0ae34b9d8
|
||||
@@ -47,6 +47,12 @@ void Update()
|
||||
{
|
||||
cameraController.RotateCam();
|
||||
}
|
||||
|
||||
// TODO: Add actual save feature later, this is just for test
|
||||
if (Input.GetKeyDown(KeyCode.I))
|
||||
{
|
||||
SaveSystem.Save();
|
||||
}
|
||||
}
|
||||
|
||||
ApplyGravity();
|
||||
|
||||
Reference in New Issue
Block a user