|
@ -19,19 +19,26 @@ public class DarknessController : MonoBehaviour |
|
|
[SerializeField, BoxGroup("Settings")] |
|
|
[SerializeField, BoxGroup("Settings")] |
|
|
private float m_lightSpeed = 1.0f; |
|
|
private float m_lightSpeed = 1.0f; |
|
|
|
|
|
|
|
|
|
|
|
[SerializeField, BoxGroup("Settings")] |
|
|
|
|
|
private AnimationCurve m_lightCurve = AnimationCurve.Linear(0,0,1,1); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[ShowNonSerializedField] |
|
|
|
|
|
private float m_currentDarknessLevel = 1; |
|
|
[ShowNonSerializedField] |
|
|
[ShowNonSerializedField] |
|
|
private float m_currentDarknessLevel; |
|
|
|
|
|
private bool m_isDarknessChanging; |
|
|
private bool m_isDarknessChanging; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void OnEnable() |
|
|
private void OnEnable() |
|
|
{ |
|
|
{ |
|
|
m_isInputDown.OnValueChanged += OnInputChange; |
|
|
m_isInputDown.OnValueChanged += OnInputChange; |
|
|
|
|
|
m_darknessMat.SetFloat("_Apply",1); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
private void OnDisable() |
|
|
private void OnDisable() |
|
|
{ |
|
|
{ |
|
|
m_isInputDown.OnValueChanged -= OnInputChange; |
|
|
m_isInputDown.OnValueChanged -= OnInputChange; |
|
|
|
|
|
m_darknessMat.SetFloat("_Apply", 1); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -39,9 +46,17 @@ public class DarknessController : MonoBehaviour |
|
|
{ |
|
|
{ |
|
|
StopAllCoroutines(); |
|
|
StopAllCoroutines(); |
|
|
if (value) |
|
|
if (value) |
|
|
StartCoroutine(ChangeDarkness(0, m_darknessSpeed)); |
|
|
|
|
|
|
|
|
{ if (!m_isDarknessChanging) |
|
|
|
|
|
{ |
|
|
|
|
|
StartCoroutine(ChangeDarkness(0, m_darknessSpeed)); |
|
|
|
|
|
} |
|
|
|
|
|
else |
|
|
|
|
|
{ |
|
|
|
|
|
StartCoroutine(ChangeDarkness(0, 0)); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
else |
|
|
else |
|
|
StartCoroutine(ChangeDarkness(1, m_lightSpeed)); |
|
|
|
|
|
|
|
|
StartCoroutine(ChangeDarkness(1, m_lightSpeed, m_lightCurve)); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -52,24 +67,26 @@ public class DarknessController : MonoBehaviour |
|
|
|
|
|
|
|
|
private IEnumerator ChangeDarkness(float end, float time, AnimationCurve curve) |
|
|
private IEnumerator ChangeDarkness(float end, float time, AnimationCurve curve) |
|
|
{ |
|
|
{ |
|
|
|
|
|
|
|
|
float start = m_currentDarknessLevel; |
|
|
float start = m_currentDarknessLevel; |
|
|
float elapsedTime = 0; |
|
|
float elapsedTime = 0; |
|
|
|
|
|
|
|
|
time = Mathf.InverseLerp(start, end, m_currentDarknessLevel); |
|
|
|
|
|
|
|
|
time = Mathf.InverseLerp(end, start, m_currentDarknessLevel) * time; |
|
|
|
|
|
|
|
|
m_isDarknessChanging = true; |
|
|
m_isDarknessChanging = true; |
|
|
|
|
|
|
|
|
while(elapsedTime < time) |
|
|
|
|
|
|
|
|
while(elapsedTime < time || time != 0) |
|
|
{ |
|
|
{ |
|
|
|
|
|
|
|
|
m_currentDarknessLevel = Mathf.Lerp(start, end, curve.Evaluate(elapsedTime / time)); |
|
|
m_currentDarknessLevel = Mathf.Lerp(start, end, curve.Evaluate(elapsedTime / time)); |
|
|
m_darknessMat.SetFloat("_Apply", m_currentDarknessLevel); |
|
|
m_darknessMat.SetFloat("_Apply", m_currentDarknessLevel); |
|
|
yield return new WaitForEndOfFrame(); |
|
|
yield return new WaitForEndOfFrame(); |
|
|
elapsedTime += Time.deltaTime; |
|
|
elapsedTime += Time.deltaTime; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
m_isDarknessChanging = false; |
|
|
|
|
|
m_currentDarknessLevel = end; |
|
|
m_currentDarknessLevel = end; |
|
|
|
|
|
m_darknessMat.SetFloat("_Apply", m_currentDarknessLevel); |
|
|
|
|
|
m_isDarknessChanging = false; |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|