time to bed

This commit is contained in:
2023-03-08 13:40:01 +02:00
parent 1c8876c99c
commit bcaa786e7c
7 changed files with 1362 additions and 38 deletions
+37 -4
View File
@@ -1,8 +1,13 @@
using System;
using System.Collections;
using UnityEngine;
public class TimeManager : MonoBehaviour
{
public static TimeManager Instance { get; private set; }
private const float MINUTE_TIME = 0.5f;
public static Action OnMinuteChanged;
[SerializeField]
@@ -22,16 +27,31 @@ public class TimeManager : MonoBehaviour
private float _timer;
private float _sunInitialIntensity;
[SerializeField]
private float _minuteToRealTime = 0.05f;
private float _minuteToRealTime;
private static TimeSpan _currentTime;
public static TimeSpan CurrentTime => _currentTime;
private TimeSpan _timeToStop;
private Action _callBackOnFastForward;
private void Awake()
{
if (Instance == null)
{
Instance = this;
DontDestroyOnLoad(gameObject);
}
else
Destroy(gameObject);
}
// Start is called before the first frame update
void Start()
{
// _sunInitialIntensity = _sunLight.intensity;
// _sunInitialIntensity = _sunLight.intensity;
_timer = _minuteToRealTime;
_currentTime = TimeSpan.Zero + TimeSpan.FromHours(_startHour);
_sunriseTime = TimeSpan.FromHours(_sunriseHour);
@@ -53,10 +73,23 @@ public class TimeManager : MonoBehaviour
_currentTime = _currentTime.Add(TimeSpan.FromMinutes(1));
OnMinuteChanged?.Invoke();
if (_currentTime.TotalMinutes >= _timeToStop.TotalMinutes)
{
_minuteToRealTime = MINUTE_TIME;
_timeToStop = TimeSpan.MaxValue;
_callBackOnFastForward.Invoke();
}
_timer = _minuteToRealTime;
}
}
public void FastForward(TimeSpan timeToStop,Action callBack)
{
_timeToStop = _currentTime.Add(timeToStop);
_minuteToRealTime = 0.03f;
_callBackOnFastForward= callBack;
}
private void RotateSun()
{
float intensityMultiplier = 1;
@@ -73,7 +106,7 @@ public class TimeManager : MonoBehaviour
{
intensityMultiplier = 0;
}
// _sunLight.intensity = _sunInitialIntensity * intensityMultiplier;
// _sunLight.intensity = _sunInitialIntensity * intensityMultiplier;
}
private TimeSpan CalculateTimeDifference(TimeSpan from, TimeSpan to)