Sunday, September 25, 2022
HomeGame Developmentc# - Unity altering alpha of TMPro textual content chauses noticeable body...

c# – Unity altering alpha of TMPro textual content chauses noticeable body price drop


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


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

IEnumerator DoShowPage(int index)
{
    yield return FadeText(textMesh, 1, 0, fadeDuration);
    textAnimator.SetText(logTextRenderer.GetFormattedPageText(LogStore.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 startTime = Time.unscaledTime;

    whereas (true)
    {
        float elapsed = Time.unscaledTime - startTime;
        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;
}

Each time it’s known as, my sport noticeably lags, the body price drops considerably.
The textual content is a number of paragraphs lengthy, largely hidden inside a scroll rect.

I attempted a Canvas group on the Textual content GO, but it surely disabled interactions.

Whats one of the best ways to strategy this?

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments