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-07 00:12:15 +02:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Wie viele Sekunden ein Tag im Spiel hat
|
|
|
|
|
/// </summary>
|
|
|
|
|
public double SecondsPerDay => _secondsPerDay;
|
|
|
|
|
|
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 19:24:26 +02:00
|
|
|
|
public double CalculateActualDeveloperTime(DifficultySettings difficultySettings, int developerCount)
|
2024-04-04 22:57:07 +02:00
|
|
|
|
{
|
2024-04-05 19:24:26 +02:00
|
|
|
|
return (_daysUntilRelease * _secondsPerDay * developerCount) / difficultySettings.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-05 14:22:16 +02:00
|
|
|
|
double oldTotalTime = _totalTime;
|
|
|
|
|
|
2024-04-04 22:57:07 +02:00
|
|
|
|
_totalTime += Time.deltaTime / _secondsPerDay;
|
2024-04-04 19:41:19 +02:00
|
|
|
|
|
2024-04-05 14:22:16 +02:00
|
|
|
|
if (Math.Floor(oldTotalTime) < Math.Floor(_totalTime))
|
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
|
|
|
|
}
|
|
|
|
|
}
|