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);
    }
Exemple #2
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);
    }
    public void StartConversation(TextAsset dialogue, Vector3 speakerPosition, Transform cameraPosition = null, AfterDialogueEvent afterEvent = null)
    {
        DialogueEngine.InitializeGenerators(SpeakingLine.CreateSpeakingLine, InstructionLine.CreateInstructionLine);
        List <ScriptLine> lines             = DialogueEngine.CreateDialogueComponents(dialogue.text);
        Dialogue          processedDialogue = new Dialogue(lines);

        StartCoroutine(PlayConversation(processedDialogue, cameraPosition, afterEvent));
    }
Exemple #4
0
    public void StartConversation(TextAsset dialogue, Vector3 focusPosition, Transform playerPosition = null, Transform cameraPosition = null, AfterDialogueEvent afterEvent = null, List <DialogueInstruction> AvailableInstructions = null)
    {
        DialogueEngine.InitializeGenerators(SpeakingLine.CreateSpeakingLine, ExpressionLine.CreateInstructionLine, ChoiceLine.GenerateChoiceLine, InstructionLine.GenerateInstructionline, StallLine.GenerateStallLine, ReisenGameManager.instance.ConditionsSatisfied);
        List <ScriptLine> lines             = DialogueEngine.CreateDialogueComponents(dialogue.text, AvailableInstructions);
        HashSet <string>  speakers          = new HashSet <string>(lines.Select(x => x.speaker).Distinct());
        Dialogue          processedDialogue = new Dialogue(lines, speakers);

        StartCoroutine(PlayConversation(processedDialogue, focusPosition, playerPosition, cameraPosition, afterEvent));
    }