blob: da571d3ecbb3efede375964e4fc6d9aaf59fa892 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
|
using System.Collections;
using UnityEngine;
[RequireComponent(typeof(Light))]
public class DaytimeSensitiveLight : MonoBehaviour, DayNightCycle.IDaytimeSensitive
{
[SerializeField]
private Color dayColor = Color.white;
[SerializeField]
private Color sunsetColor;
[SerializeField]
private Color nightColor;
[SerializeField]
private float dayToSunsetDuration = 2f;
[SerializeField]
private float sunsetToNightDuration = 2f;
private Light targetLight;
private void Start()
{
targetLight = GetComponent<Light>();
DayNightCycle.Instance.RegisterDaytimeSensitiveObject(this);
}
public void OnDawn_AfterSunrise()
{
}
public void OnDusk()
{
StopAllCoroutines();
StartCoroutine(ToNight());
}
public void OnDawn_BeforeSunrise()
{
StopAllCoroutines();
StartCoroutine(ToDay());
}
private IEnumerator ToDay()
{
float timer2 = 0f;
while (timer2 <= sunsetToNightDuration)
{
timer2 += Time.deltaTime;
targetLight.color = Color.Lerp(nightColor, sunsetColor, timer2 / sunsetToNightDuration);
yield return null;
}
timer2 = 0f;
while (timer2 <= dayToSunsetDuration)
{
timer2 += Time.deltaTime;
targetLight.color = Color.Lerp(sunsetColor, dayColor, timer2 / dayToSunsetDuration);
yield return null;
}
targetLight.color = dayColor;
}
private IEnumerator ToNight()
{
float timer2 = 0f;
while (timer2 <= dayToSunsetDuration)
{
timer2 += Time.deltaTime;
targetLight.color = Color.Lerp(dayColor, sunsetColor, timer2 / dayToSunsetDuration);
yield return null;
}
timer2 = 0f;
while (timer2 <= sunsetToNightDuration)
{
timer2 += Time.deltaTime;
targetLight.color = Color.Lerp(dayColor, nightColor, timer2 / sunsetToNightDuration);
yield return null;
}
targetLight.color = nightColor;
}
}
|