Exemplo n.º 1
0
        //---------------------------------------------------------------------
        // Typing
        //---------------------------------------------------------------------

        /// <summary>
        /// The coroutine that handles typing out the sentence.
        /// </summary>
        /// <param name="sentence">The sentence to type.</param>
        /// <param name="autoAdvance">Whether or not to automatically advance the
        /// dialog after typing has finished.</param>
        /// <param name="delayBeforeAdvance">How long to delay before advancing the
        /// dialog, in seconds</param>
        /// <param name="speed">The speed of typing, in characters per second.</param>
        private IEnumerator _TypeSentence(string sentence, bool autoAdvance, float delayBeforeAdvance, float speed, bool animateSpeaker)
        {
            manager.StillWriting = true;
            TalkingSound.Play();

            if (animateSpeaker)
            {
                DialogManager.StartTalking(currentCharacter);
            }

            ClearText();

            float waitTime = 1 / speed;

            if (sentence != null)
            {
                for (int i = 0; i < sentence.Length; i++)
                {
                    char c = sentence[i];
                    TypeCharacter(c);

                    // Waiting for any time after the sentence is finished opens the door
                    // for a race condition.
                    if (i < sentence.Length - 1)
                    {
                        if (DialogManager.Punctuation.ContainsKey(c))
                        {
                            TalkingSound.Stop();
                            yield return(new WaitForSeconds(DialogManager.Punctuation[c]));

                            TalkingSound.Play();
                        }
                        else
                        {
                            yield return(new WaitForSeconds(waitTime));
                        }
                    }
                }
            }

            TryListDecisions();

            if (animateSpeaker)
            {
                DialogManager.StopTalking(currentCharacter);
            }

            TalkingSound.Stop();
            manager.StillWriting = false;

            if (delayBeforeAdvance > 0)
            {
                yield return(new WaitForSeconds(delayBeforeAdvance));
            }

            if (autoAdvance)
            {
                DialogManager.ContinueDialog();
            }
        }