Greatest Time simulation ever
Außerdem: - Coole Singletons, möglicherweise die geilsten Singletons, die jemals in Unity implementiert wurden - Utility Klassen nach Utility Verschoben - Schlaganfallsymptome in Developer entfernt
This commit is contained in:
67
3d Prototyp/Assets/Scripts/TimeManager.cs
Normal file
67
3d Prototyp/Assets/Scripts/TimeManager.cs
Normal file
@ -0,0 +1,67 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
using Utility;
|
||||
|
||||
public class TimeManager : MonoBehaviourSingleton<TimeManager>
|
||||
{
|
||||
[SerializeField]
|
||||
private int _daysUntilRelease = 30;
|
||||
|
||||
[SerializeField]
|
||||
private double _secondsPerDay = 48;
|
||||
|
||||
[SerializeField]
|
||||
private double _dayTime = 0.0;
|
||||
|
||||
[SerializeField] private Light _sun;
|
||||
|
||||
[SerializeField]
|
||||
private Weekday _currentWeekday;
|
||||
|
||||
public int DaysLeft => _daysUntilRelease;
|
||||
|
||||
public double DayTime => _dayTime;
|
||||
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
||||
[SerializeField, ShowOnly]
|
||||
private string stringgy;
|
||||
|
||||
void Update()
|
||||
{
|
||||
if (GameManager.Instance.IsGameRunning)
|
||||
{
|
||||
UpdateTime();
|
||||
UpdateSun();
|
||||
}
|
||||
}
|
||||
|
||||
void UpdateTime()
|
||||
{
|
||||
_dayTime += Time.deltaTime / _secondsPerDay;
|
||||
|
||||
if (_dayTime >= 1.0)
|
||||
{
|
||||
_dayTime -= 1.0;
|
||||
_daysUntilRelease--;
|
||||
_currentWeekday = _currentWeekday.GetNext();
|
||||
}
|
||||
|
||||
stringgy = TimeOfDay.ToString();
|
||||
}
|
||||
|
||||
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));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user