Пример #1
0
        protected virtual IEnumerator ProcessTokens(List <TextTagToken> tokens, bool stopAudio, Action onComplete)
        {
            // Reset control members
            boldActive              = false;
            italicActive            = false;
            colorActive             = false;
            sizeActive              = false;
            colorText               = "";
            sizeValue               = 16f;
            currentPunctuationPause = punctuationPause;
            currentWritingSpeed     = writingSpeed;

            exitFlag  = false;
            isWriting = true;

            TokenType previousTokenType = TokenType.Invalid;

            for (int i = 0; i < tokens.Count; ++i)
            {
                // Pause between tokens if Paused is set
                while (Paused)
                {
                    yield return(null);
                }

                var token = tokens[i];

                // Notify listeners about new token
                WriterSignals.DoTextTagToken(this, token, i, tokens.Count);

                switch (token.type)
                {
                case TokenType.Words:
                    yield return(StartCoroutine(DoWords(token.paramList, previousTokenType)));

                    break;

                case TokenType.BoldStart:
                    boldActive = true;
                    break;

                case TokenType.BoldEnd:
                    boldActive = false;
                    break;

                case TokenType.ItalicStart:
                    italicActive = true;
                    break;

                case TokenType.ItalicEnd:
                    italicActive = false;
                    break;

                case TokenType.ColorStart:
                    if (CheckParamCount(token.paramList, 1))
                    {
                        colorActive = true;
                        colorText   = token.paramList[0];
                    }
                    break;

                case TokenType.ColorEnd:
                    colorActive = false;
                    break;

                case TokenType.SizeStart:
                    if (TryGetSingleParam(token.paramList, 0, 16f, out sizeValue))
                    {
                        sizeActive = true;
                    }
                    break;

                case TokenType.SizeEnd:
                    sizeActive = false;
                    break;

                case TokenType.Wait:
                    yield return(StartCoroutine(DoWait(token.paramList)));

                    break;

                case TokenType.WaitForInputNoClear:
                    yield return(StartCoroutine(DoWaitForInput(false)));

                    break;

                case TokenType.WaitForInputAndClear:
                    yield return(StartCoroutine(DoWaitForInput(true)));

                    break;

                case TokenType.WaitOnPunctuationStart:
                    TryGetSingleParam(token.paramList, 0, punctuationPause, out currentPunctuationPause);
                    break;

                case TokenType.WaitOnPunctuationEnd:
                    currentPunctuationPause = punctuationPause;
                    break;

                case TokenType.Clear:
                    Text = "";
                    break;

                case TokenType.SpeedStart:
                    TryGetSingleParam(token.paramList, 0, writingSpeed, out currentWritingSpeed);
                    break;

                case TokenType.SpeedEnd:
                    currentWritingSpeed = writingSpeed;
                    break;

                case TokenType.Exit:
                    exitFlag = true;
                    break;

                case TokenType.Message:
                    if (CheckParamCount(token.paramList, 1))
                    {
                        Flowchart.BroadcastFungusMessage(token.paramList[0]);
                    }
                    break;

                case TokenType.VerticalPunch:
                {
                    float vintensity;
                    float time;
                    TryGetSingleParam(token.paramList, 0, 10.0f, out vintensity);
                    TryGetSingleParam(token.paramList, 1, 0.5f, out time);
                    Punch(new Vector3(0, vintensity, 0), time);
                }
                break;

                case TokenType.HorizontalPunch:
                {
                    float hintensity;
                    float time;
                    TryGetSingleParam(token.paramList, 0, 10.0f, out hintensity);
                    TryGetSingleParam(token.paramList, 1, 0.5f, out time);
                    Punch(new Vector3(hintensity, 0, 0), time);
                }
                break;

                case TokenType.Punch:
                {
                    float intensity;
                    float time;
                    TryGetSingleParam(token.paramList, 0, 10.0f, out intensity);
                    TryGetSingleParam(token.paramList, 1, 0.5f, out time);
                    Punch(new Vector3(intensity, intensity, 0), time);
                }
                break;

                case TokenType.Flash:
                    float flashDuration;
                    TryGetSingleParam(token.paramList, 0, 0.2f, out flashDuration);
                    Flash(flashDuration);
                    break;

                case TokenType.Audio:
                {
                    AudioSource audioSource = null;
                    if (CheckParamCount(token.paramList, 1))
                    {
                        audioSource = FindAudio(token.paramList[0]);
                    }
                    if (audioSource != null)
                    {
                        audioSource.PlayOneShot(audioSource.clip);
                    }
                }
                break;

                case TokenType.AudioLoop:
                {
                    AudioSource audioSource = null;
                    if (CheckParamCount(token.paramList, 1))
                    {
                        audioSource = FindAudio(token.paramList[0]);
                    }
                    if (audioSource != null)
                    {
                        audioSource.Play();
                        audioSource.loop = true;
                    }
                }
                break;

                case TokenType.AudioPause:
                {
                    AudioSource audioSource = null;
                    if (CheckParamCount(token.paramList, 1))
                    {
                        audioSource = FindAudio(token.paramList[0]);
                    }
                    if (audioSource != null)
                    {
                        audioSource.Pause();
                    }
                }
                break;

                case TokenType.AudioStop:
                {
                    AudioSource audioSource = null;
                    if (CheckParamCount(token.paramList, 1))
                    {
                        audioSource = FindAudio(token.paramList[0]);
                    }
                    if (audioSource != null)
                    {
                        audioSource.Stop();
                    }
                }
                break;
                }

                previousTokenType = token.type;

                if (exitFlag)
                {
                    break;
                }
            }

            inputFlag         = false;
            exitFlag          = false;
            isWaitingForInput = false;
            isWriting         = false;

            NotifyEnd(stopAudio);

            if (onComplete != null)
            {
                onComplete();
            }
        }
Пример #2
0
        protected virtual IEnumerator ProcessTokens(List <TextTagToken> tokens, bool stopAudio, System.Action onComplete)
        {
            // Reset control members
            boldActive              = false;
            italicActive            = false;
            colorActive             = false;
            sizeActive              = false;
            WordTokensFound         = tokens.Count(x => x.type == TokenType.Words);
            WordTokensProcessed     = 0;
            colorText               = "";
            sizeValue               = 16f;
            currentPunctuationPause = punctuationPause;
            currentWritingSpeed     = writingSpeed;

            exitFlag  = false;
            isWriting = true;

            TokenType previousTokenType = TokenType.Invalid;

            for (int i = 0; i < tokens.Count; ++i)
            {
                // Pause between tokens if Paused is set
                while (Paused)
                {
                    yield return(null);
                }

                var token = tokens[i];

                // Notify listeners about new token
                WriterSignals.DoTextTagToken(this, token, i, tokens.Count);

                // Update the read ahead string buffer. This contains the text for any
                // Word tags which are further ahead in the list.
                if (doReadAheadText)
                {
                    readAheadString.Length = 0;
                    for (int j = i + 1; j < tokens.Count; ++j)
                    {
                        var readAheadToken = tokens[j];

                        if (readAheadToken.type == TokenType.Words &&
                            readAheadToken.paramList.Count == 1)
                        {
                            readAheadString.Append(readAheadToken.paramList[0]);
                        }
                        else if (readAheadToken.type == TokenType.WaitForInputAndClear)
                        {
                            break;
                        }
                    }
                }

                switch (token.type)
                {
                case TokenType.Words:
                    yield return(StartCoroutine(DoWords(token.paramList, previousTokenType)));

                    WordTokensProcessed++;
                    break;

                case TokenType.BoldStart:
                    boldActive = true;
                    break;

                case TokenType.BoldEnd:
                    boldActive = false;
                    break;

                case TokenType.ItalicStart:
                    italicActive = true;
                    break;

                case TokenType.ItalicEnd:
                    italicActive = false;
                    break;

                case TokenType.ColorStart:
                    if (CheckParamCount(token.paramList, 1))
                    {
                        colorActive = true;
                        colorText   = token.paramList[0];
                    }
                    break;

                case TokenType.ColorEnd:
                    colorActive = false;
                    break;

                case TokenType.LinkStart:
                    if (CheckParamCount(token.paramList, 1))
                    {
                        linkActive = true;
                        linkText   = token.paramList[0];
                    }
                    break;

                case TokenType.LinkEnd:
                    linkActive = false;
                    break;

                case TokenType.SizeStart:
                    if (TryGetSingleParam(token.paramList, 0, 16f, out sizeValue))
                    {
                        sizeActive = true;
                    }
                    break;

                case TokenType.SizeEnd:
                    sizeActive = false;
                    break;

                case TokenType.Wait:
                    yield return(StartCoroutine(DoWait(token.paramList)));

                    break;

                case TokenType.WaitForInputNoClear:
                    yield return(StartCoroutine(DoWaitForInput(false)));

                    break;

                case TokenType.WaitForInputAndClear:
                    yield return(StartCoroutine(DoWaitForInput(true)));

                    break;

                case TokenType.WaitForVoiceOver:
                    yield return(StartCoroutine(DoWaitVO()));

                    break;

                case TokenType.WaitOnPunctuationStart:
                    TryGetSingleParam(token.paramList, 0, punctuationPause, out currentPunctuationPause);
                    break;

                case TokenType.WaitOnPunctuationEnd:
                    currentPunctuationPause = punctuationPause;
                    break;

                case TokenType.Clear:
                    textAdapter.Text = "";
                    break;

                case TokenType.SpeedStart:
                    TryGetSingleParam(token.paramList, 0, writingSpeed, out currentWritingSpeed);
                    break;

                case TokenType.SpeedEnd:
                    currentWritingSpeed = writingSpeed;
                    break;

                case TokenType.Exit:
                    exitFlag = true;
                    break;

                case TokenType.Message:
                    if (CheckParamCount(token.paramList, 1))
                    {
                        Flowchart.BroadcastFungusMessage(token.paramList[0]);
                    }
                    break;

                case TokenType.VerticalPunch:
                {
                    float vintensity;
                    float time;
                    TryGetSingleParam(token.paramList, 0, 10.0f, out vintensity);
                    TryGetSingleParam(token.paramList, 1, 0.5f, out time);
                    Punch(new Vector3(0, vintensity, 0), time);
                }
                break;

                case TokenType.HorizontalPunch:
                {
                    float hintensity;
                    float time;
                    TryGetSingleParam(token.paramList, 0, 10.0f, out hintensity);
                    TryGetSingleParam(token.paramList, 1, 0.5f, out time);
                    Punch(new Vector3(hintensity, 0, 0), time);
                }
                break;

                case TokenType.Punch:
                {
                    float intensity;
                    float time;
                    TryGetSingleParam(token.paramList, 0, 10.0f, out intensity);
                    TryGetSingleParam(token.paramList, 1, 0.5f, out time);
                    Punch(new Vector3(intensity, intensity, 0), time);
                }
                break;

                case TokenType.Flash:
                    float flashDuration;
                    TryGetSingleParam(token.paramList, 0, 0.2f, out flashDuration);
                    Flash(flashDuration);
                    break;

                case TokenType.Audio:
                {
                    AudioSource audioSource = null;
                    if (CheckParamCount(token.paramList, 1))
                    {
                        audioSource = FindAudio(token.paramList[0]);
                    }
                    if (audioSource != null)
                    {
                        audioSource.PlayOneShot(audioSource.clip);
                    }
                }
                break;

                case TokenType.AudioLoop:
                {
                    AudioSource audioSource = null;
                    if (CheckParamCount(token.paramList, 1))
                    {
                        audioSource = FindAudio(token.paramList[0]);
                    }
                    if (audioSource != null)
                    {
                        audioSource.Play();
                        audioSource.loop = true;
                    }
                }
                break;

                case TokenType.AudioPause:
                {
                    AudioSource audioSource = null;
                    if (CheckParamCount(token.paramList, 1))
                    {
                        audioSource = FindAudio(token.paramList[0]);
                    }
                    if (audioSource != null)
                    {
                        audioSource.Pause();
                    }
                }
                break;

                case TokenType.AudioStop:
                {
                    AudioSource audioSource = null;
                    if (CheckParamCount(token.paramList, 1))
                    {
                        audioSource = FindAudio(token.paramList[0]);
                    }
                    if (audioSource != null)
                    {
                        audioSource.Stop();
                    }
                }
                break;
                }

                previousTokenType = token.type;

                if (exitFlag)
                {
                    break;
                }
            }

            inputFlag         = false;
            exitFlag          = false;
            isWaitingForInput = false;
            isWriting         = false;

            NotifyEnd(stopAudio);

            if (onComplete != null)
            {
                onComplete();
            }
        }