|
|
|
|
|
|
ToBlack = 1 |
|
|
|
} |
|
|
|
|
|
|
|
public enum FadeTimingMode |
|
|
|
{ |
|
|
|
UnscaledGameTime, |
|
|
|
GameTime, |
|
|
|
} |
|
|
|
|
|
|
|
public void Fade(float duration, FadeMode mode, Callable[] OnComplete, GameObject instigator = null) |
|
|
|
public void Fade(float duration, FadeMode mode, FadeTimingMode timingMode, Callable[] OnComplete, GameObject instigator = null) |
|
|
|
{ |
|
|
|
if (m_Coroutine != null) |
|
|
|
{ |
|
|
|
|
|
|
switch (mode) |
|
|
|
{ |
|
|
|
case FadeMode.ToBlack: |
|
|
|
m_Coroutine = StartCoroutine(FadeCoroutine(duration, 1.0f, 1.0f, OnComplete, instigator)); |
|
|
|
m_Coroutine = StartCoroutine(FadeCoroutine(duration, 1.0f, 1.0f, timingMode, OnComplete, instigator)); |
|
|
|
m_Coroutine = StartCoroutine(FadeCoroutine(duration, 0.0f, -1.0f, OnComplete, instigator)); |
|
|
|
m_Coroutine = StartCoroutine(FadeCoroutine(duration, 0.0f, -1.0f, timingMode, OnComplete, instigator)); |
|
|
|
break; |
|
|
|
default: throw new NotImplementedException(); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
IEnumerator FadeCoroutine(float duration, float target, float sign, Callable[] OnComplete, GameObject instigator) |
|
|
|
IEnumerator FadeCoroutine(float duration, float target, float sign, FadeTimingMode timingMode, Callable[] OnComplete, GameObject instigator) |
|
|
|
{ |
|
|
|
FullScreenFadePlane.gameObject.SetActive(true); |
|
|
|
Color c = FullScreenFadePlane.color; |
|
|
|
|
|
|
float t; |
|
|
|
switch (timingMode) |
|
|
|
{ |
|
|
|
case FadeTimingMode.GameTime: |
|
|
|
t = Time.deltaTime; |
|
|
|
break; |
|
|
|
default: |
|
|
|
case FadeTimingMode.UnscaledGameTime: |
|
|
|
t = Time.unscaledDeltaTime; |
|
|
|
break; |
|
|
|
} |
|
|
|
c.a += sign * Time.unscaledDeltaTime / duration; |
|
|
|
c.a += sign * t / duration; |
|
|
|
FullScreenFadePlane.color = c; |
|
|
|
yield return new WaitForEndOfFrame(); |
|
|
|
} |
|
|
|