Ejemplo n.º 1
0
        public void Fade()
        {
            BeginAnimation(OpacityProperty, null);
            FadeStarted?.Invoke(this, EventArgs.Empty);
            var anim = new DoubleAnimation(0, new Duration(TimeSpan.FromSeconds(0.2)))
            {
                FillBehavior = FillBehavior.Stop
            };

            anim.Completed += (sender, args) =>
            {
                Opacity = 0;
                Faded?.Invoke(this, args);
            };
            BeginAnimation(OpacityProperty, anim);
        }
Ejemplo n.º 2
0
    IEnumerator FadeCoroutine(float duration, float targetOpacity, Color color)
    {
        Debug.Log("Fading!");
        // Announce this is happening.
        FadeEventArgs fadeArgs = new FadeEventArgs();

        fadeArgs.targetOpacity = targetOpacity;

        // When this fader gets invisible, the screen is being faded in. When it gets
        // fully-opaque, it's being faded out.
        if (targetOpacity == 0)
        {
            fadeArgs.fadeTarget = FadeStyle.fadeIn;
        }
        else if (targetOpacity == 1)
        {
            fadeArgs.fadeTarget = FadeStyle.fadeOut;
        }

        FadeStarted.Invoke(fadeArgs);

        // Decide how the fading will be done, and apply the color.

        float timer       = 0;
        float baseOpacity = alpha;

        // Do the fading over time.
        while (timer < duration)
        {
            timer += Time.deltaTime;
            alpha  = Mathf.Lerp(baseOpacity, targetOpacity,
                                timer / duration);
            yield return(null);
        }

        alpha = targetOpacity;                                                                                                 // In case the duration is 0.

        // Announce this is done.
        FadeEnded.Invoke(fadeArgs);
        coroutine = null;
    }
Ejemplo n.º 3
0
 protected virtual void OnFadeStarted(FadeEventArgs e)
 {
     FadeStarted?.Invoke(this, e);
 }