using System; using UnityEngine; using UnityEngine.Serialization; using Utility; public class TimeManager : MonoBehaviourSingleton { [SerializeField] private int _daysUntilRelease = 30; [SerializeField] private double _secondsPerDay = 48; [FormerlySerializedAs("_dayTime")] [SerializeField] private double _totalTime = 0.0; [SerializeField] private Light _sun; private DateTime _startDate; private DateTime _deadline; public int DaysLeft => _daysUntilRelease; public DayOfWeek CurrentDayOfWeek => CurrentDate.DayOfWeek; public TimeSpan TimeOfDay => CurrentDate.TimeOfDay; /// /// Das Datum zu dem das Spiel begonnen hat. /// public DateTime StartDate => _startDate; /// /// Das aktuelle Datum und Uhrzeit im Spiel. /// public DateTime CurrentDate => _startDate.AddDays(_totalTime); /// /// Die Deadline des Spiels. /// public DateTime Deadline => _deadline; public DateTime PredictedEndDate { get { double realSeconds = GameManager.Instance.ExpectedRemainingGameDuration; double gameDays = realSeconds / _secondsPerDay; return CurrentDate.AddDays(gameDays); } } public bool PredictedMissesDeadline => PredictedEndDate > Deadline; /// /// Wie viele Sekunden ein Tag im Spiel hat /// public double SecondsPerDay => _secondsPerDay; /// /// Gibt true zurück, wenn die Deadline verpasst wurde. /// public bool MissedDeadline => CurrentDate > Deadline; public void Init() { _startDate = new DateTime(2024, 4, 2, 12, 0, 0); _deadline = _startDate.AddDays(_daysUntilRelease); } /// /// Berechnet die (real life) Sekunden, die die Entwickler bei 100% Effizienz benötigen um das Spiel bei gegebener Schwierigkeit zu entwickeln. /// public double CalculateActualDeveloperTime(DifficultySettings difficultySettings, int developerCount) { return (_daysUntilRelease * _secondsPerDay * developerCount) / difficultySettings.DaysUntilReleaseFactor; } void Update() { if (GameManager.Instance.IsGameRunning) { UpdateTime(); UpdateSun(); } } void UpdateTime() { double oldTotalTime = _totalTime; _totalTime += Time.deltaTime / _secondsPerDay; if (Math.Floor(oldTotalTime) < Math.Floor(_totalTime)) { _daysUntilRelease--; } } private void UpdateSun() { float currentTime = (float)TimeOfDay.TotalDays; _sun.transform.rotation = Quaternion.Euler(new Vector3(Mathf.LerpAngle(-90, 60, (float)Math.Sin(currentTime * Math.PI)), (float)(currentTime * 360.0), 0)); } }