2024-04-04 19:41:19 +02:00
|
|
|
|
using System;
|
|
|
|
|
using UnityEngine;
|
2024-04-04 22:57:07 +02:00
|
|
|
|
using UnityEngine.Serialization;
|
2024-04-04 19:41:19 +02:00
|
|
|
|
using Utility;
|
|
|
|
|
|
|
|
|
|
public class TimeManager : MonoBehaviourSingleton<TimeManager>
|
|
|
|
|
{
|
|
|
|
|
[SerializeField]
|
|
|
|
|
private int _daysUntilRelease = 30;
|
|
|
|
|
|
|
|
|
|
[SerializeField]
|
|
|
|
|
private double _secondsPerDay = 48;
|
|
|
|
|
|
2024-04-04 22:57:07 +02:00
|
|
|
|
[FormerlySerializedAs("_dayTime")] [SerializeField]
|
|
|
|
|
private double _totalTime = 0.0;
|
2024-04-04 19:41:19 +02:00
|
|
|
|
|
|
|
|
|
[SerializeField] private Light _sun;
|
|
|
|
|
|
2024-04-04 22:57:07 +02:00
|
|
|
|
private DateTime _startDate;
|
|
|
|
|
private DateTime _deadline;
|
|
|
|
|
|
2024-04-04 19:41:19 +02:00
|
|
|
|
public int DaysLeft => _daysUntilRelease;
|
|
|
|
|
|
2024-04-05 13:54:38 +02:00
|
|
|
|
public DayOfWeek CurrentDayOfWeek => CurrentDate.DayOfWeek;
|
2024-04-04 19:41:19 +02:00
|
|
|
|
|
2024-04-04 22:57:07 +02:00
|
|
|
|
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;
|
2024-04-04 19:41:19 +02:00
|
|
|
|
|
2024-04-04 22:57:07 +02:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gibt true zurück, wenn die Deadline verpasst wurde.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public bool MissedDeadline => CurrentDate > Deadline;
|
|
|
|
|
|
|
|
|
|
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>
|
2024-04-05 13:54:38 +02:00
|
|
|
|
public double CalculateActualDeveloperTime(Difficulty difficulty, int developerCount)
|
2024-04-04 22:57:07 +02:00
|
|
|
|
{
|
|
|
|
|
DifficultySettings settings = difficulty.GetSettings();
|
|
|
|
|
|
2024-04-05 13:54:38 +02:00
|
|
|
|
return (_daysUntilRelease * _secondsPerDay * developerCount) / settings.DaysUntilReleaseFactor;
|
2024-04-04 22:57:07 +02:00
|
|
|
|
}
|
2024-04-04 19:41:19 +02:00
|
|
|
|
|
|
|
|
|
void Update()
|
|
|
|
|
{
|
|
|
|
|
if (GameManager.Instance.IsGameRunning)
|
|
|
|
|
{
|
|
|
|
|
UpdateTime();
|
|
|
|
|
UpdateSun();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void UpdateTime()
|
|
|
|
|
{
|
2024-04-04 22:57:07 +02:00
|
|
|
|
_totalTime += Time.deltaTime / _secondsPerDay;
|
2024-04-04 19:41:19 +02:00
|
|
|
|
|
2024-04-04 22:57:07 +02:00
|
|
|
|
if (_totalTime >= 1.0)
|
2024-04-04 19:41:19 +02:00
|
|
|
|
{
|
2024-04-04 22:57:07 +02:00
|
|
|
|
_totalTime -= 1.0;
|
2024-04-04 19:41:19 +02:00
|
|
|
|
_daysUntilRelease--;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void UpdateSun()
|
|
|
|
|
{
|
2024-04-04 22:57:07 +02:00
|
|
|
|
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));
|
2024-04-04 19:41:19 +02:00
|
|
|
|
}
|
|
|
|
|
}
|