Home Game Development c# – Unity fading alpha of TMPro textual content causes noticeable body fee drop

c# – Unity fading alpha of TMPro textual content causes noticeable body fee drop

0
c# – Unity fading alpha of TMPro textual content causes noticeable body fee drop

[ad_1]

I’m utilizing this code to alter the transparency of my TMPro TMPUGUI textual content when altering a web page (from a guide).


// known as in begin, and on button press
public void ShowPage(int index, bool ignoreFade=false)
{
    if (changeWithFade && !ignoreFade)
    {
        if (isFading) 
        {
            Debug.Log("LogViewBehaviour: Still fading, motion cancelled!");
            return;
        }
        isFading = true;
        StartCoroutine(DoShowPage(index));
    }
    else
    {
        textAnimator.SetText("", false);
        textAnimator.SetText(logTextRenderer.GetFormattedPageText(LogRetailer.GetPageByIndex(index)), false);
        StartCoroutine(ScrollToBottom());
        currentPage = index;
   }
}

IEnumerator DoShowPage(int index)
{
    yield return FadeText(textMesh, 1, 0, fadeDuration);
    textAnimator.SetText(logTextRenderer.GetFormattedPageText(LogRetailer.GetPageByIndex(index)), false);
    currentPage = index;
    yield return ScrollToBottom(); 
    yield return FadeText(textMesh, 0, 1, fadeDuration);
    isFading = false;
}

IEnumerator FadeText(TMPro.TextMeshProUGUI sourceToFade, float startAlpha, float endAlpha, float period)
{
    float beginTime = Time.unscaledTime;

    whereas (true)
    {
        float elapsed = Time.unscaledTime - beginTime;
        float t = elapsed / period;

        sourceToFade.alpha = Mathf.Clamp01(Mathf.Lerp(startAlpha, endAlpha, t));

        if (sourceToFade.alpha == endAlpha)
        {
            break;
        }

        yield return null;
    }//finish whereas
}

IEnumerator ScrollToBottom()
{
    yield return new WaitForEndOfFrame();
    scrollRect.verticalNormalizedPosition = 0f;
}

Every time that is executed, my sport noticeably lags, the body fee drops considerably till the fade is completed.
The textual content is a number of paragraphs lengthy, largely hidden inside a scroll rect.

I attempted a Canvas group on the textual content gameobject, nevertheless it disabled interactions.

What’s one of the simplest ways to strategy this?

[ad_2]

LEAVE A REPLY

Please enter your comment!
Please enter your name here