Example #1
0
 public void SetAlphaOnFader(Fader fader, float alpha)
 {
     if (fader)
     {
         fader.SetAlpha(alpha);
     }
 }
Example #2
0
        public IEnumerator FadeContent(Fader content, FadeType fadeType, float fadeDuration, AnimationCurve opacityCurve, float fadeTimeOffset = 0.0f)
        {
            if (content == null)
            {
                // Invoke callback to notify end of fade
                if (OnFadeComplete != null)
                {
                    OnFadeComplete.Invoke(fadeType);
                }

                yield break;
            }

            // Wait for the fade time offset to complete before alpha is changed on the faders
            float time = fadeTimeOffset;

            while (time > 0.0f)
            {
                time = Mathf.Clamp(time - Time.deltaTime, 0.0f, fadeTimeOffset);
                yield return(null);
            }

            // Setup initial and final alpha values for the fade based on the type of fade
            Vector2 alpha        = (fadeType == FadeType.FadeIn) ? Vector2.up : Vector2.right;
            float   timeFraction = 0.0f;

            content.EnableFade();

            do
            {
                time        += Time.deltaTime;
                timeFraction = Mathf.Clamp01(time / fadeDuration);

                float alphaValue = opacityCurve != null?Mathf.Lerp(alpha.x, alpha.y, Mathf.Clamp01(opacityCurve.Evaluate(timeFraction))) : timeFraction;

                content.SetAlpha(alphaValue);

                yield return(null);
            }while (timeFraction < 1.0f && content != null);

            content.DisableFade();

            // Invoke callback to notify end of fade
            if (OnFadeComplete != null)
            {
                OnFadeComplete.Invoke(fadeType);
            }
        }