imp. sun system
This commit is contained in:
@@ -38,6 +38,7 @@ public class TimeManager : MonoBehaviour
|
||||
private TimeSpan _sunsetTime;
|
||||
|
||||
private float _timer;
|
||||
private float _sunInitialIntensity;
|
||||
|
||||
[SerializeField]
|
||||
private float _minuteToRealTime = 0.05f;
|
||||
@@ -48,6 +49,7 @@ public class TimeManager : MonoBehaviour
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
_sunInitialIntensity = _sunLight.intensity;
|
||||
_timer = _minuteToRealTime;
|
||||
_currentTime = TimeSpan.Zero + TimeSpan.FromHours(_startHour);
|
||||
_sunriseTime = TimeSpan.FromHours(_sunriseHour);
|
||||
@@ -75,36 +77,23 @@ public class TimeManager : MonoBehaviour
|
||||
|
||||
private void RotateSun()
|
||||
{
|
||||
|
||||
float sunLightRotation;
|
||||
float intensityMultiplier = 1;
|
||||
float timeofDay = (float)CurrentTime.TotalSeconds / 86400;
|
||||
_sunLight.transform.localRotation = Quaternion.Euler((timeofDay * 360f) - 90, 170, 0);
|
||||
if (_currentTime > _sunriseTime && _currentTime < _sunsetTime)
|
||||
{
|
||||
TimeSpan sunriseToSunsetDuration = CalculateTimeDifference(_sunriseTime, _sunsetTime);
|
||||
TimeSpan timeSinceSunrise = CalculateTimeDifference(_sunriseTime, _currentTime);
|
||||
|
||||
double percentage = timeSinceSunrise.TotalMinutes / sunriseToSunsetDuration.TotalMinutes;
|
||||
|
||||
sunLightRotation = Mathf.Lerp(0, 180, (float)percentage);
|
||||
if (timeofDay <= 0.25f)
|
||||
intensityMultiplier = Mathf.Clamp01((timeofDay - 0.23f) * (1 / 0.02f));
|
||||
if (timeofDay >= 0.73f)
|
||||
intensityMultiplier = Mathf.Clamp01(1 - (timeofDay - 0.73f) * (1 / 0.02f));
|
||||
}
|
||||
else
|
||||
{
|
||||
TimeSpan nightDuration = CalculateTimeDifference(_sunsetTime, _sunriseTime);
|
||||
TimeSpan timeSinceSunset = CalculateTimeDifference(_sunsetTime, _currentTime);
|
||||
|
||||
double percentage = timeSinceSunset.TotalMinutes / nightDuration.TotalMinutes;
|
||||
|
||||
sunLightRotation = Mathf.Lerp(180, 360, (float)percentage);
|
||||
intensityMultiplier = 0;
|
||||
}
|
||||
_sunLight.transform.rotation = Quaternion.AngleAxis(sunLightRotation, Vector3.right);
|
||||
_sunLight.intensity = _sunInitialIntensity * intensityMultiplier;
|
||||
}
|
||||
|
||||
private void UpdateLightSettings()
|
||||
{
|
||||
float dotProduct = Vector3.Dot(_sunLight.transform.forward, Vector3.down);
|
||||
_sunLight.intensity = Mathf.Lerp(0, _maxSunLightIntensity, _lightChangeCurve.Evaluate(dotProduct));
|
||||
_moonLight.intensity = Mathf.Lerp(_maxMoonLightIntensity, 0, _lightChangeCurve.Evaluate(dotProduct));
|
||||
RenderSettings.ambientLight = Color.Lerp(_nightAmbientLight, _dayAmbientLight, _lightChangeCurve.Evaluate(dotProduct));
|
||||
}
|
||||
private TimeSpan CalculateTimeDifference(TimeSpan from, TimeSpan to)
|
||||
{
|
||||
TimeSpan diff = to - from;
|
||||
|
||||
Reference in New Issue
Block a user