More betterer Time tracking and basic Win/Lose check

This commit is contained in:
Simon Lübeß
2024-04-04 22:57:07 +02:00
parent 1d7a3d5870
commit 93db8ae9e5
10 changed files with 1414 additions and 27 deletions

View File

@ -1,5 +1,6 @@
using System;
using UnityEngine;
using UnityEngine.Serialization;
using Utility;
public class TimeManager : MonoBehaviourSingleton<TimeManager>
@ -10,32 +11,61 @@ public class TimeManager : MonoBehaviourSingleton<TimeManager>
[SerializeField]
private double _secondsPerDay = 48;
[SerializeField]
private double _dayTime = 0.0;
[FormerlySerializedAs("_dayTime")] [SerializeField]
private double _totalTime = 0.0;
[SerializeField] private Light _sun;
[SerializeField]
private Weekday _currentWeekday;
private DateTime _startDate;
private DateTime _deadline;
public int DaysLeft => _daysUntilRelease;
public double DayTime => _dayTime;
public Weekday CurrentWeekday => _currentWeekday;
public TimeSpan TimeOfDay
{
get
{
double hour = _dayTime * 24.0;
double minute = hour * 60;
double seconds = minute * 60;
return new TimeSpan((int)Math.Floor(hour), (int)Math.Floor(minute % 60), (int)Math.Floor(seconds % 60));
}
}
public TimeSpan TimeOfDay => CurrentDate.TimeOfDay;
/// <summary>
/// Das Datum zu dem das Spiel begonnen hat.
/// </summary>
public DateTime StartDate => _startDate;
/// <summary>
/// Das aktuelle Datum und Uhrzeit im Spiel.
/// </summary>
public DateTime CurrentDate => _startDate.AddDays(_totalTime);
/// <summary>
/// Die Deadline des Spiels.
/// </summary>
public DateTime Deadline => _deadline;
/// <summary>
/// Gibt true zurück, wenn die Deadline verpasst wurde.
/// </summary>
public bool MissedDeadline => CurrentDate > Deadline;
[SerializeField, ShowOnly]
private string stringgy;
public void Init()
{
_startDate = new DateTime(2024, 4, 2, 12, 0, 0);
_deadline = _startDate.AddDays(_daysUntilRelease);
}
/// <summary>
/// Berechnet die (real life) Sekunden, die die Entwickler bei 100% Effizienz benötigen um das Spiel bei gegebener Schwierigkeit zu entwickeln.
/// </summary>
public double CalculateActualDeveloperTime(Difficulty difficulty)
{
DifficultySettings settings = difficulty.GetSettings();
return _daysUntilRelease * _secondsPerDay / settings.DaysUntilReleaseFactor;
}
void Update()
{
@ -48,11 +78,11 @@ public class TimeManager : MonoBehaviourSingleton<TimeManager>
void UpdateTime()
{
_dayTime += Time.deltaTime / _secondsPerDay;
_totalTime += Time.deltaTime / _secondsPerDay;
if (_dayTime >= 1.0)
if (_totalTime >= 1.0)
{
_dayTime -= 1.0;
_totalTime -= 1.0;
_daysUntilRelease--;
_currentWeekday = _currentWeekday.GetNext();
}
@ -62,6 +92,8 @@ public class TimeManager : MonoBehaviourSingleton<TimeManager>
private void UpdateSun()
{
_sun.transform.rotation = Quaternion.Euler(new Vector3(Mathf.LerpAngle(-90, 60, (float)Math.Sin(_dayTime * Math.PI)), (float)(_dayTime * 360.0), 0));
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));
}
}