Пример #1
0
 //Change this based on the game implementation
 public override void PerformLine()
 {
     try
     {
         // very per game specific stuff
         CharacterDialogueAnimator speakerAnimator = GameObject.Find(speaker).GetComponent <CharacterDialogueAnimator>();
         if (speakerAnimator == null)
         {
             speakerAnimator = GameObject.Find(speaker).GetComponentInChildren <CharacterDialogueAnimator>();
         }
         speakerAnimator.changeExpression(desiredExpression);
     }
     catch (Exception e)
     {
         Debug.Log("attempted speaker for this expression is " + speaker);
         throw e;
     }
 }
Пример #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);
    }