Пример #1
0
    public IEnumerator FadeOut()
    {
        isFading = true;
        //set oppacity to one to initialise fade in
        float oppacity = 1f;


        //start fading in tutorial prompts
        while (oppacity > 0f)
        {
            //Simultaneously fade in image elements
            oppacity -= 1f / 100f;

            foreach (Image image in images)
            {
                if (oppacity <= image.color.a)//Only decrease alpha of image
                {
                    image.color = new Color(image.color.r, image.color.g, image.color.b, oppacity);
                }
            }
            foreach (TextMeshProUGUI txt in texts)
            {
                if (oppacity <= txt.color.a)//Only decrease alpha of image
                {
                    txt.color = new Color(txt.color.r, txt.color.g, txt.color.b, oppacity);
                }
            }

            //ensure background oppacity does not exceed given max
            if (oppacity <= maxLimitedOppacity)
            {
                foreach (Image limited in limitedImages)
                {
                    limited.color = new Color(limited.color.r, limited.color.g, limited.color.b, oppacity);
                }
            }

            yield return(new WaitForSeconds(fadeOutRate));
        }

        //at the end reset each value
        foreach (Image image in images)
        {
            image.color = new Color(image.color.r, image.color.g, image.color.b, 0f);
        }
        foreach (Image limited in limitedImages)
        {
            limited.color = new Color(limited.color.r, limited.color.g, limited.color.b, 0f);
        }
        foreach (TextMeshProUGUI txt in texts)
        {
            txt.color = new Color(txt.color.r, txt.color.g, txt.color.b, 0f);
        }
        //call complete
        isFading = false;
        OnFadeComplete?.Invoke(gameObject);
    }
Пример #2
0
    private IEnumerator FadeIn()
    {
        float oppacity = 0;

        cam.SetActive(true);
        loadingScreen.SetActive(true);
        loadingText.SetActive(false);
        screenImage.color = new Color(screenImage.color.r, screenImage.color.g, screenImage.color.b, 0f);


        while (oppacity < 1f)
        {
            oppacity         += 0.01f;
            screenImage.color = new Color(screenImage.color.r, screenImage.color.g, screenImage.color.b, oppacity);
            yield return(new WaitForSeconds(fadeRate));
        }
        loadingText.SetActive(true);
        OnFadeComplete?.Invoke();
    }
Пример #3
0
    private IEnumerator FadeIn()
    {
        isFading = true;
        //set oppacity to zero to initialise fade in
        float oppacity = 0f;

        foreach (Image image in images)
        {
            image.color = new Color(image.color.r, image.color.g, image.color.b, oppacity);
        }
        foreach (Image limited in limitedImages)
        {
            limited.color = new Color(limited.color.r, limited.color.g, limited.color.b, oppacity);
        }
        foreach (TextMeshProUGUI txt in texts)
        {
            txt.color = new Color(txt.color.r, txt.color.g, txt.color.b, oppacity);
        }

        //start fading in elements
        while (oppacity < 1f)
        {
            oppacity += 1f / 100f;
            foreach (Image image in images)
            {
                image.color = new Color(image.color.r, image.color.g, image.color.b, oppacity);
            }
            foreach (TextMeshProUGUI txt in texts)
            {
                txt.color = new Color(txt.color.r, txt.color.g, txt.color.b, oppacity);
            }

            //ensure background oppacity does not exceed given max
            if (oppacity <= maxLimitedOppacity)
            {
                foreach (Image limited in limitedImages)
                {
                    limited.color = new Color(limited.color.r, limited.color.g, limited.color.b, oppacity);
                }
            }

            yield return(new WaitForSeconds(fadeInRate));
        }

        //at the end reset each value
        foreach (Image image in images)
        {
            image.color = new Color(image.color.r, image.color.g, image.color.b, 1f);
        }
        foreach (Image limited in limitedImages)
        {
            limited.color = new Color(limited.color.r, limited.color.g, limited.color.b, maxLimitedOppacity);
        }
        foreach (TextMeshProUGUI txt in texts)
        {
            txt.color = new Color(txt.color.r, txt.color.g, txt.color.b, 1f);
        }

        //call complete
        isFading = false;
        OnFadeComplete?.Invoke(gameObject);
    }