コード例 #1
0
    /// <summary>
    /// The actual conversation part of the conversation; gets a list of lines for a ghost to say and has him say them.
    /// Z key advances to next line
    /// X key mid-line fills the line in instead of waiting slowly to fill it in
    /// </summary>
    /// <param name="dialogue">
    /// A message for the ghost to say.
    /// </param>
    private IEnumerator conversationInit(GhostMessage dialogue)
    {
        follower.ghostConversation(focusPoint);

        // if the ghost being talked to wasn't assigned a message, pick a random one
        if (dialogue == null)
        {
            dialogue = new GhostMessage();
            dialogue.AddRandomMessage();
        }

        // run through each of the lines of dialogue for the ghost to say
        for (int index = 0; index < dialogue.messages.Count; index++)
        {
            skipDialogue = false;
            nextLine     = false;

            endOfLine = false;

            // convert the current line to a list of chars
            char[] lineLetters = dialogue.messages[index].message.ToCharArray();
            textShadow.effectDistance = new Vector2(0, dialogue.messages[index].size / -7.69f);

            // slowly fill the current line in using these chars
            for (int letter = 0; letter < lineLetters.Length; letter++)
            {
                // if the player presses the x key, fill all the dialogue in and break this loop
                if (skipDialogue)
                {
                    for (int position = letter; position < lineLetters.Length; position++)
                    {
                        PrintedDialogue += lineLetters[position];
                    }
                    break;
                }

                PrintedDialogue      += lineLetters[letter];
                dialogueText.fontSize = dialogue.messages[index].size;

                yield return(new WaitForSeconds(dialogue.messages[index].playLength));
            }

            // update the status of the dialogue so the player now has a chance to go to the next line
            endOfLine = true;

            // once the line is fully filled in, wait for the player to press the z key to advance to the next line
            while (!nextLine)
            {
                yield return(new WaitForSeconds(.1f));
            }

            // go to the next line
            PrintedDialogue = "";
        }

        // once the ghost has said of all of his lines, end the conversation
        endConversation();
    }