示例#1
0
    internal IEnumerator PlayCutscene()
    {
        if (!string.IsNullOrWhiteSpace(cutsceneMusic))
        {
            AudioMaster.instance.PlayTrack(cutsceneMusic);
        }

        int lineTracker = 0;

        //string currentSpeaker = "";
        while (!dialogue.IsFinished)
        {
            ScriptLine line = dialogue.GetNextLine();
            line.PerformLine();

            while (!line.IsFinished())
            {
                yield return(null);
            }
            lineTracker++;
        }
    }
示例#2
0
    internal IEnumerator PlayConversation(Dialogue dialogue, Transform cameraPosition = null, AfterDialogueEvent afterEvent = null)
    {
        // If a special camera position was provided, tell the camera man to use it.
        ConversationPause();

        /*
         * CameraMan cameraMan = FindObjectOfType<CameraMan>();
         * if (cameraPosition != null)
         *  cameraMan.StartCinematicMode(cameraPosition);
         */

        GameObject player = GameObject.FindGameObjectWithTag("Player");

        player.GetComponent <CharacterDialogueAnimator>().startTalking();

        DialogueBubbleUI.instance.init(dialogue);

        //Dictionary<string, DialogueAnimator> speakerDict = DialogueEngine.GetSpeakers(dialogue.text).ToDictionary(x => x, x => GameObject.Find(x).GetComponent<DialogueAnimator>());

        int lineTracker = 0;

        //string currentSpeaker = "";
        while (!dialogue.IsFinished)
        {
            ScriptLine line = dialogue.GetNextLine();
            line.PerformLine();
            while (!line.IsFinished())
            {
                if (Input.GetKeyDown(KeyCode.LeftArrow))
                {
                    lineTracker--;
                    StartCoroutine(DialogueBubbleUI.instance.animateLogs(lineTracker));
                }
                if (Input.GetKeyDown(KeyCode.RightArrow))
                {
                    lineTracker++;
                    StartCoroutine(DialogueBubbleUI.instance.animateLogs(lineTracker));
                }
                yield return(null);
            }
            lineTracker++;

            /*
             * string currentLine = dialogueLines[lineTracker];
             * if (currentLine.StartsWith("[expression]"))
             * {
             *  print(currentLine);
             *  var expressionString = currentLine.Split(' ')[1];
             *  var expression = (CharacterExpressionAnimator.Expressions)Enum.Parse(typeof(CharacterExpressionAnimator.Expressions), expressionString);
             *  player.GetComponent<CharacterDialogueAnimator>().changeExpression(expression);
             * }
             * else
             * {
             *  string speaker = DialogueEngine.GetSpeaker(currentLine);
             *  string spokenLine = DialogueEngine.GetSpokenLine(currentLine);
             *  if (speaker != "")
             *      currentSpeaker = speaker;
             *  else if (currentSpeaker == "")
             *      Debug.LogWarning("Speaker not specified");
             *  Vector3 speakerPosition = speakerDict[currentSpeaker].getSpeechOrigin();
             *
             *  DialogueUIController.instance.displaySpeechBubble(spokenLine, speakerPosition);
             *  while (!DialogueUIController.instance.ready)
             *      yield return null;
             * }
             * lineTracker++;
             */
        }
        DialogueBubbleUI.instance.finishDialogue();
        player.GetComponent <CharacterDialogueAnimator>().stopTalking();

        while (!DialogueBubbleUI.instance.ready)
        {
            yield return(null);
        }

        ConversationUnpause();

        /*
         * cameraMan.EndCinematicMode();
         */

        afterEvent();
        yield return(null);
    }
示例#3
0
    internal IEnumerator PlayConversation(Dialogue dialogue, Vector3 focusPosition, Transform playerPosition = null, Transform cameraPosition = null, AfterDialogueEvent afterEvent = null)
    {
        // If a special camera position was provided, tell the camera man to use it.
        ConversationPause();

        //External library dependency
        CameraMan cameraMan = FindObjectOfType <CameraMan>();

        // Start Cinematic Mode right away
        if (cameraPosition != null)
        {
            cameraMan.StartCinematicMode(cameraPosition);
            // Don't wait for Camera yet. Let forced player movement start working.
        }

        GameObject player = GameObject.FindGameObjectWithTag("Player");

        if (playerPosition != null)
        {
            // Locate the other speaker
            GameObject otherSpeaker = null;
            foreach (string speakerName in dialogue.speakers)
            {
                GameObject speakerObject = GameObject.Find(speakerName);
                if (speakerObject != player)
                {
                    otherSpeaker = speakerObject;
                }
            }

            SetNpcCollisionBoxes(otherSpeaker, false); // Disable NPC collision boxes while player is moving.
            yield return(player.GetComponent <CharacterMovement>().moveCharacter(playerPosition.position, focusPosition - playerPosition.position, 6f));

            SetNpcCollisionBoxes(otherSpeaker, true);

            // If no cinematic camera position was given, and there is another "speaker" (probably an NPC),
            // put the camera into a magic "dialogue angle"
            if (cameraPosition == null && otherSpeaker != null)
            {
                Vector3 cameraOffset            = new Vector3(0f, 2f, -4.5f); // Magical camera offset vector for 4:3 size.
                Vector3 midpointBetweenSpeakers = (otherSpeaker.transform.position + player.transform.position) * .5f;
                cameraMan.StartCinematicMode(midpointBetweenSpeakers + cameraOffset, Quaternion.identity);
            }
        }

        // Wait for Camera to be in place before we start initializing dialogue options.
        while (!cameraMan.InDesiredPosition())
        {
            yield return(null);
        }

        DialogueBubbleUI.instance.init(dialogue);

        //Dictionary<string, DialogueAnimator> speakerDict = DialogueEngine.GetSpeakers(dialogue.text).ToDictionary(x => x, x => GameObject.Find(x).GetComponent<DialogueAnimator>());

        int        lineTracker = 0;
        GameObject speaker     = null;

        //string currentSpeaker = "";
        while (!dialogue.IsFinished)
        {
            ScriptLine line       = dialogue.GetNextLine();
            GameObject newSpeaker = GameObject.Find(line.speaker);
            if (newSpeaker != null)
            {
                if (newSpeaker != speaker)
                {
                    speaker?.GetComponentInChildren <CharacterDialogueAnimator>()?.stopTalking();
                    speaker = newSpeaker;
                }
                speaker.GetComponentInChildren <CharacterDialogueAnimator>()?.startTalking();
                speaker.GetComponentInChildren <CharacterDialogueAnimator>()?.Turn(focusPosition.x - speaker.transform.position.x);
            }

            line.PerformLine();

            while (!line.IsFinished())
            {
                /* disabled for now
                 * if (Input.GetKeyDown(KeyCode.LeftArrow))
                 * {
                 *  lineTracker--;
                 *  StartCoroutine(DialogueBubbleUI.instance.animateLogs(lineTracker));
                 * }
                 * if (Input.GetKeyDown(KeyCode.RightArrow))
                 * {
                 *  lineTracker++;
                 *  StartCoroutine(DialogueBubbleUI.instance.animateLogs(lineTracker));
                 * }
                 */
                yield return(null);
            }
            lineTracker++;
        }
        DialogueBubbleUI.instance.finishDialogue();
        CharacterDialogueAnimator playerCda = player.GetComponent <CharacterDialogueAnimator>();

        playerCda.stopTalking();
        playerCda.changeExpression(CharacterExpression.normal);

        while (!DialogueBubbleUI.instance.ready)
        {
            yield return(null);
        }

        foreach (string speakerName in dialogue.speakers)
        {
            GameObject newSpeaker = GameObject.Find(speakerName);
            speaker?.GetComponentInChildren <CharacterDialogueAnimator>()?.stopTalking();
        }


        cameraMan.EndCinematicMode();
        // No need to wait for CameraMan

        ConversationUnpause();

        afterEvent();
        yield return(null);
    }