partial fix sun system
This commit is contained in:
@@ -40,15 +40,16 @@ public class TimeManager : MonoBehaviour
|
||||
private float _timer;
|
||||
|
||||
[SerializeField]
|
||||
private float _minuteToRealTime = 0.01f;
|
||||
private float _minuteToRealTime = 0.05f;
|
||||
|
||||
public static TimeSpan CurrentTime { get; private set; }
|
||||
private static TimeSpan _currentTime;
|
||||
public static TimeSpan CurrentTime => _currentTime;
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
_timer = _minuteToRealTime;
|
||||
CurrentTime = TimeSpan.Zero + TimeSpan.FromHours(_startHour);
|
||||
_currentTime = TimeSpan.Zero + TimeSpan.FromHours(_startHour);
|
||||
_sunriseTime = TimeSpan.FromHours(_sunriseHour);
|
||||
_sunsetTime = TimeSpan.FromHours(_sunsetHour);
|
||||
}
|
||||
@@ -57,7 +58,7 @@ public class TimeManager : MonoBehaviour
|
||||
void Update()
|
||||
{
|
||||
UpdateTime();
|
||||
//RotateSun();
|
||||
RotateSun();
|
||||
}
|
||||
|
||||
private void UpdateTime()
|
||||
@@ -65,36 +66,37 @@ public class TimeManager : MonoBehaviour
|
||||
_timer -= Time.deltaTime;
|
||||
if (_timer <= 0)
|
||||
{
|
||||
CurrentTime = CurrentTime.Add(TimeSpan.FromMinutes(1));
|
||||
_currentTime = _currentTime.Add(TimeSpan.FromMinutes(1));
|
||||
OnMinuteChanged?.Invoke();
|
||||
|
||||
_timer = _minuteToRealTime;
|
||||
}
|
||||
}
|
||||
|
||||
//private void RotateSun()
|
||||
//{
|
||||
// float sunLightRotation;
|
||||
// if (_currentTime.TimeOfDay > _sunriseTime && _currentTime.TimeOfDay < _sunsetTime)
|
||||
// {
|
||||
// TimeSpan sunriseToSunsetDuration = CalculateTimeDifference(_sunriseTime, _sunsetTime);
|
||||
// TimeSpan timeSinceSunrise = CalculateTimeDifference(_sunriseTime, _currentTime.TimeOfDay);
|
||||
private void RotateSun()
|
||||
{
|
||||
|
||||
// double percentage = timeSinceSunrise.TotalMinutes / sunriseToSunsetDuration.TotalMinutes;
|
||||
float sunLightRotation;
|
||||
if (_currentTime > _sunriseTime && _currentTime < _sunsetTime)
|
||||
{
|
||||
TimeSpan sunriseToSunsetDuration = CalculateTimeDifference(_sunriseTime, _sunsetTime);
|
||||
TimeSpan timeSinceSunrise = CalculateTimeDifference(_sunriseTime, _currentTime);
|
||||
|
||||
// sunLightRotation = Mathf.Lerp(0, 180, (float)percentage);
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// TimeSpan nightDuration = CalculateTimeDifference(_sunsetTime, _sunriseTime);
|
||||
// TimeSpan timeSinceSunset = CalculateTimeDifference(_sunsetTime, _currentTime.TimeOfDay);
|
||||
double percentage = timeSinceSunrise.TotalMinutes / sunriseToSunsetDuration.TotalMinutes;
|
||||
|
||||
// double percentage = timeSinceSunset.TotalMinutes / nightDuration.TotalMinutes;
|
||||
sunLightRotation = Mathf.Lerp(0, 180, (float)percentage);
|
||||
}
|
||||
else
|
||||
{
|
||||
TimeSpan nightDuration = CalculateTimeDifference(_sunsetTime, _sunriseTime);
|
||||
TimeSpan timeSinceSunset = CalculateTimeDifference(_sunsetTime, _currentTime);
|
||||
|
||||
// sunLightRotation = Mathf.Lerp(180, 360, (float)percentage);
|
||||
// }
|
||||
// _sunLight.transform.rotation = Quaternion.AngleAxis(sunLightRotation, Vector3.right);
|
||||
//}
|
||||
double percentage = timeSinceSunset.TotalMinutes / nightDuration.TotalMinutes;
|
||||
|
||||
sunLightRotation = Mathf.Lerp(180, 360, (float)percentage);
|
||||
}
|
||||
_sunLight.transform.rotation = Quaternion.AngleAxis(sunLightRotation, Vector3.right);
|
||||
}
|
||||
|
||||
private void UpdateLightSettings()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user