Exemple #1
0
    //Scene() is the primary Coroutine for looping through lines of a conversation when the player talks to a character.

    //I modified this system designed by my co-programmer to, for each frame, check that frame's EmoteCheck class.

    //If the class says an emote should be played here, it then begins FindEmote() to find the correct character

    //and activate the correct emote.

    IEnumerator Scene()
    {
        //Debug.Log("Scene Started");
        //interactHandle = gameController.interactInput;

        if (dialogueManager != null)
        {
            //Debug.Log("Still working?");
            dialogueManager.hasActiveDialogue = true;
        }

        for (int i = 0; i < Frames.Length; i++)
        {
            frameIndex = i;
            //  Debug.Log("Depth Level 1");
            if (i != 0)
            {
                Frames[i - 1].SetActive(false);
            }
            Frames[i].SetActive(true);
            emoteCheck = Frames[i].GetComponent <EmoteCheck>();
            if (emoteCheck != null)
            {
                if (emoteCheck.play == true)
                {
                    StartCoroutine(FindEmote());
                }
            }

            yield return(new WaitForEndOfFrame());

            // Wait while the text hasn't finished or the player interacts to finish the text
            yield return(new WaitUntil(() => (Input.GetButtonDown(gameController.interactInput) || (hasFinishedDisplayingText || currentTextDisplayer == null))));

            if (i == Frames.Length - 1)
            {
                textIsDone = true;
            }

            //      Debug.Log("Depth Level 3");
            if (/*Input.GetButtonDown("Interact") ||*/ hasFinishedDisplayingText || currentTextDisplayer == null)
            {
                hasFinishedDisplayingText = false;
                currentTextDisplayer      = null;

                // Check if the Frame has a DialogueOption
                Frame tempFrame = Frames[i].GetComponent <Frame>();
                if (tempFrame != null)
                {
                    //Debug.Log("Unlocking Now!");
                    camControl.lockPosition = true;
                    Cursor.lockState        = CursorLockMode.None;
                    //Debug.Log("Can You See Me?");
                    Cursor.visible = true;
                    //Debug.Log("Cursor Unlocked");
                    if (tempFrame.dialogueButtons.firstSelectedGameObject != tempFrame.firstButton)
                    {
                        tempFrame.dialogueButtons.firstSelectedGameObject = tempFrame.firstButton;
                    }
                    yield return(new WaitWhile(() => tempFrame.Get_ShouldWait() == true));

                    //Debug.Log("Cursor Frozen");
                    camControl.lockPosition = false;
                    Cursor.lockState        = CursorLockMode.Locked;
                    Cursor.visible          = false;

                    if (tempFrame.Get_ShouldContinue() == false)
                    {
                        i = Frames.Length + 2;
                        break;
                    }
                    else
                    {
                        continue; // This skips the need to press the interact key again
                    }
                }
                else
                {
                    yield return(new WaitUntil(() => Input.GetButtonDown(gameController.interactInput)));
                }

                continue; // This continues to the next frame
            }
            else
            {
                currentTextDisplayer.DisplayFullText();
                //Wait for text to display full text
                yield return(new WaitForSeconds(0.1f));

                // Check if the Frame has a DialogueOption
                Frame tempFrame = Frames[i].GetComponent <Frame>();
                if (tempFrame != null)
                {
                    Debug.Log("Unlocking Now!");
                    Cursor.lockState = CursorLockMode.None;
                    Debug.Log("Can You See Me?");
                    Cursor.visible = true;
                    Debug.Log("Cursor Unlocked");
                    yield return(new WaitWhile(() => tempFrame.Get_ShouldWait() == true));

                    Debug.Log("Cursor Frozen");
                    Cursor.lockState = CursorLockMode.Locked;
                    Cursor.visible   = false;
                    //tempFrame.Reset_ShouldWait();

                    if (tempFrame.Get_ShouldContinue() == false)
                    {
                        i = Frames.Length + 2;
                        //tempFrame.Reset_ShouldWait();
                        break;
                    }
                    else
                    {
                        tempFrame.Reset_ShouldWait();
                        continue; // This skips the need to press the interact key again
                    }
                }
            }



            yield return(new WaitUntil(() => Input.GetButtonDown(gameController.interactInput)));


            #region OldCode
            //yield return new WaitForEndOfFrame();
            //while (true)
            //{
            ////    Debug.Log("Depth Level 2");
            //    // TODO: Extremely high polling number for user input
            //    yield return new WaitForSeconds(0.00001f);
            //    if (Input.GetButtonDown("Interact"))
            //    {
            //  //      Debug.Log("Depth Level 3");
            //        if (hasFinishedDisplayingText || currentTextDisplayer == null)
            //        {
            //            hasFinishedDisplayingText = false;
            //            currentTextDisplayer = null;
            //            break;
            //        }
            //        else
            //        {
            //            currentTextDisplayer.DisplayFullText();
            //            //Wait for text to display full text
            //            yield return new WaitForSeconds(0.1f);


            //            while (true)
            //            {
            //    //            Debug.Log("Depth Level 4");
            //                // TODO: Extremely high polling number for user input
            //                yield return new WaitForSeconds(0.00001f);
            //                if (Input.GetButtonDown("Interact"))
            //                {
            //      //              Debug.Log("Depth Level 5");
            //                    break;
            //                }
            //            }

            //            break;
            //        }

            //    }
            //}
            #endregion
        }

        hasFinishedDisplayingText = false;
        Frames[Frames.Length - 1].SetActive(false);


        //The for loop below is a bit of a back-door solution to allow the player to properly exit a cinematic event which changes the camera angles per line of dialogue.

        //I needed a reference all the way back to the character the player was actually talking to in the moment to make this work. Though not designed originally to

        //perform this function, the Emote system's architecture allowed me access back to the character that would have otherwise necessitated the creation of additional functionality.

        for (int i = 0; i < dialogueManager.npcs.Length; i++)
        {
            if (NPC == dialogueManager.npcs[i].NPC)
            {
                dialogueManager.npcs[i].npcEmotes.interactable.doneTalking = true;
            }
        }

        //Calls on Event_Trigger to start a cam event
        //KNOWN BUG: Currently is causing the next (or last) frame of dialogue to repeat during cam event.
        //Debug.Log("Dialogue is done!");
        if (dialogueManager.prepCamEvent && isCamEventActive)
        {
            //dialogueManager.hasActiveDialogue = false;
            eventTrigger.InitiateEvent();
            yield return(new WaitUntil(() => eventTrigger.GetEventCam().startScene == false));
        }

        if (dialogueManager != null)
        {
            dialogueManager.hasActiveDialogue = false;
        }

        dialogueCam.RestPosition();

        //Camera.main.orthographicSize = tempNum;
        yield return(null);
    }