예제 #1
0
    public void FadeCanvasGroupOut(CanvasGroup canvasGroup, Action callback)
    {
        // Find out if the renderer we want to fade is already fading
        KeyValuePair <CanvasGroup, Coroutine> existingFade = Instance.FadingRenderers.Find(renderCoroutinePair => renderCoroutinePair.Key == canvasGroup);

        // If it's already fading, stop the fade
        if (existingFade.Equals(default(KeyValuePair <CanvasRenderer, Coroutine>)) && existingFade.Value != null)
        {
            Instance.StopCoroutine(existingFade.Value);
        }

        // Setup a new fade routine for the renderer
        Coroutine fade = null;
        KeyValuePair <CanvasGroup, Coroutine> replacementFade = new KeyValuePair <CanvasGroup, Coroutine>(canvasGroup, fade);

        Action completionAction = () => {
            Instance.FadingRenderers.Remove(replacementFade);
            Instance.CurrentOverlays.Remove(canvasGroup);
            if (callback != null)
            {
                callback();
            }
        };

        fade = Instance.StartCoroutine(FadeUtility.UIAlphaFade(canvasGroup, canvasGroup.alpha, 0f, FadeDuration, FadeUtility.EaseType.InOut, completionAction));

        Instance.FadingRenderers.Remove(existingFade);  // Remove the previous fade
        Instance.FadingRenderers.Add(replacementFade);  // Add the new fade
    }
예제 #2
0
    void Update()
    {
        this.Duration -= Time.deltaTime;

        if (this.Duration <= 0 && this.Fading == null)
        {
            this.Fading = StartCoroutine(FadeUtility.UIAlphaFade(this.CanvasGroup, this.CanvasGroup.alpha, 0, FadeDuration, FadeUtility.EaseType.InOut, () => { this.Fading = null; this.Remove(); }));
        }
    }
예제 #3
0
    public void Show(string tooltip, float duration)
    {
        if (!GUIManager.Instance.Tooltips.Contains(this))
        {
            GUIManager.Instance.Tooltips.Add(this);
        }

        this.Duration  = duration;
        this.Text.text = tooltip;

        if (!this.FadingIn && this.CanvasGroup.alpha != 1)
        {
            if (this.Fading != null)
            {
                StopCoroutine(this.Fading);
            }

            this.Fading   = StartCoroutine(FadeUtility.UIAlphaFade(this.CanvasGroup, this.CanvasGroup.alpha, 1, FadeDuration, FadeUtility.EaseType.InOut, () => { this.Fading = null; this.FadingIn = false; }));
            this.FadingIn = true;
        }
    }