summaryrefslogtreecommitdiff
path: root/Thronefall_v1.0/Decompile/NightLight.cs
blob: affc9b037c0367a5e5d06ebdba88bcd11d7b5b0a (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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
using System.Collections;
using UnityEngine;

[RequireComponent(typeof(Light))]
public class NightLight : MonoBehaviour, DayNightCycle.IDaytimeSensitive
{
	public float targetIntensity = 0.75f;

	public float intensityFlickerRange = 0.15f;

	public float distanceFlickerRange = 5f;

	public float flickerSpeed = 1f;

	public float fadeInTime = 2.5f;

	public float fadeOutTime = 1f;

	public ParticleSystem flames;

	private float transitionTime;

	private float targetRange;

	private Light targetLight;

	private bool fullyFadedIn;

	private float currentIntensity => targetIntensity + Mathf.Lerp(0f - intensityFlickerRange, intensityFlickerRange, Mathf.PerlinNoise(Time.time * flickerSpeed, Time.time * flickerSpeed));

	private float currentRange => targetRange + Mathf.Lerp(0f - distanceFlickerRange, distanceFlickerRange, Mathf.PerlinNoise(Time.time * flickerSpeed, Time.time * flickerSpeed));

	private void Start()
	{
		transitionTime = DayNightCycle.Instance.sunriseTime;
		DayNightCycle.Instance.RegisterDaytimeSensitiveObject(this);
		targetLight = GetComponent<Light>();
		targetLight.intensity = 0f;
		targetRange = targetLight.range;
		base.gameObject.SetActive(value: false);
	}

	private void Update()
	{
		if (fullyFadedIn)
		{
			targetLight.intensity = currentIntensity;
		}
		targetLight.range = currentRange;
	}

	public void OnDawn_AfterSunrise()
	{
	}

	public void OnDawn_BeforeSunrise()
	{
		StopAllCoroutines();
		StartCoroutine(FadeLightOut());
	}

	public void OnDusk()
	{
		base.gameObject.SetActive(value: true);
		StopAllCoroutines();
		StartCoroutine(FadeLightIn());
	}

	private IEnumerator FadeLightIn()
	{
		fullyFadedIn = false;
		float clock = 0f;
		yield return new WaitForSeconds(transitionTime * 0.1f);
		flames.Play();
		while (clock < fadeInTime)
		{
			clock += Time.deltaTime;
			targetLight.intensity = currentIntensity * Mathf.InverseLerp(0f, fadeInTime, clock);
			yield return null;
		}
		targetLight.intensity = targetIntensity;
		fullyFadedIn = true;
	}

	private IEnumerator FadeLightOut()
	{
		float clock = 0f;
		flames.Stop();
		while (clock < fadeOutTime)
		{
			clock += Time.deltaTime;
			targetLight.intensity = currentIntensity * Mathf.InverseLerp(fadeOutTime, 0f, clock);
			yield return null;
		}
		targetLight.intensity = 0f;
		base.gameObject.SetActive(value: false);
	}
}