shifatkhan / ProjectAS-Unity

0 stars 0 forks source link

Typewriter effect not functioning as intended #3

Open shifatkhan opened 4 years ago

shifatkhan commented 4 years ago
  1. The typewriter effect shows any richtext tags. We only need to show the final text.
  2. If the player goes to the next Dialogue text before the previous one's typewriter effect coroutine finished, it would result in both dialogue texts getting mixed together

dialogue-bug-v1

shifatkhan commented 4 years ago

Fix 1: Rich text

Wrote an extra for loop that runs when an opening < symbol is found. Adds the found tag as a string to the TextMesh text (instead of one character at a time)

if(textToType[i] == '<')
{
    string richtext = "";
    for (int j = i; j < textToType.Length; j++)
    {
        richtext += textToType[j];
        if(textToType[j] == '>')
        {
            i = j+1;
            textMesh.text += richtext;
            break;
        }
    }
}

Fix 2: Coroutine

Simply fixed it by stopping all coroutine before starting a new dialogue with StopAllCoroutines()

shifatkhan commented 4 years ago

New issue: Typewriter's TextMeshAnimator

Right now, the TextMeshAnimator animates the letters once the Typewriter is done. Need to make it so the text animations play on the characters that are drawn already on screen.

shifatkhan commented 4 years ago

New issue: Typewriter's TextMeshAnimator (cont'd)

Combined Typewriter effect with TextMeshAnimator's animations, but it is a bit glitchy. The text moves very slightly when typing, but the actual animations starts playing the the typewriter is done.

dialogue-v4

I am calling textMeshAnimator.SyncToTextMesh() after each typed character:

    IEnumerator Typewriter()
    {
        for (int i = 0; i < textToType.Length; i++)
        {
            // Check for rich text. Skip them so typewriter effect doesn't apply.
            if(textToType[i] == '<')
            {
                string richtext = "";
                for (int j = i; j < textToType.Length; j++)
                {
                    richtext += textToType[j];
                    if(textToType[j] == '>')
                    {
                        // Hotfix for index out of bounds when we do i = j+1
                        if (j + 1 >= textToType.Length)
                            textToType += " ";

                        i = j+1;
                        textMesh.text += richtext;
                        break;
                    }
                }
            }

            textMesh.text += textToType[i];
            textMeshAnimator.SyncToTextMesh(); // *HERE

            yield return new WaitForSeconds(typingSpeed);
        }

        finishedTyping = true;
    }

Need to find a way to call textMeshAnimator.SyncToTextMesh() efficiently