Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- public class TimeManager : MonoBehaviour
- {
- public int gameDayInMinutes;
- private float m_DayInSeconds;
- private float m_CurrentTime;
- private bool m_bIsPaused = false;
- private bool m_bIsActive = true;
- private bool m_bIsDayOver = false;
- public void OnEnable()
- {
- m_DayInSeconds = gameDayInMinutes * 60.0f;
- EventManager.EndOfDayMethods += ResetGameClock;
- EnableGameClock();
- }
- public void OnDisable()
- {
- KillGameClock();
- EventManager.EndOfDayMethods -= ResetGameClock;
- }
- private IEnumerator GameClock()
- {
- while(m_bIsActive)
- {
- if(m_bIsPaused)
- {
- yield return null;
- }
- else
- {
- m_CurrentTime++;
- if(m_CurrentTime >= m_DayInSeconds)
- {
- //day is over
- m_bIsDayOver = true;
- EventManager.ResetDay();
- }
- yield return new WaitForSeconds(1.0f); //TODO: modifier here to manipulate game time speed
- }
- }
- }
- public void EnableGameClock()
- {
- m_bIsPaused = false;
- m_bIsActive = true;
- StartCoroutine(GameClock());
- }
- public void ResetGameClock()
- {
- m_bIsDayOver = true;
- m_CurrentTime = 0.0f;
- m_bIsDayOver = false;
- }
- public void PauseGameClock()
- {
- Debug.LogWarning("Game Clock Paused");
- m_bIsPaused = true;
- }
- private void ResumeGameClock()
- {
- Debug.LogWarning("Game Clock Resumed");
- m_bIsPaused = false;
- }
- private void KillGameClock()
- {
- Debug.LogWarning("Game Clock Killed");
- m_bIsActive = false;
- m_bIsPaused = false;
- }
- }
Add Comment
Please, Sign In to add comment