Exemplo n.º 1
0
        /// <summary>
        /// A method call to set and display the dialogue node content into the tempDialogueTree.
        /// </summary>
        /// <param name="dialogueTree">The dialogue tree that you are passing in from a NonMonobehavior object.</param>
        /// <param name="changeCharacterName">Used to overwrite the existing characterName string on a DialogueTree scriptable object.</param>
        public static void SetAndDisplayDialogueNodeContent(DialogueTree dialogueTree, bool changeCharacterName = false)
        {
            Debug.LogWarning("dialogueTree: " + dialogueTree);
            Debug.LogWarning("tempDialogueTree: " + tempDialogueTree);

            tempDialogueTree = (DialogueTree)ScriptableObject.CreateInstance(typeof(DialogueTree));       // Set this to the DialogueTree scriptable object that will only have a single reusable updatable node.

            // Add new dialogue node if dialogueNodeElements list count is 0
            if (tempDialogueTree.dialogueNodeElements.Count == 0)
            {
                tempDialogueTree.dialogueNodeElements.Add(new DialogueTree.DialogueNode());
            }

            // Create new dialogue node for tempDialogueTree to contain.
            DialogueTree.DialogueNode dialogueNode = new DialogueTree.DialogueNode();

            // Get reference to the characterName from the DialogueTree scriptable object that will be modified.
            if (characterName == "")
            {
                characterName = tempDialogueTree.dialogueNodeElements[0].nodeCharacterName;
            }

            // First clear existing data that was previous used in the tempDialogueTree if any
            tempDialogueTree.dialogueNodeElements.Clear();

            for (int i = 0; i < dialogueTree.dialogueNodeElements.Count; i++)
            {
                // Set the new dialogueNode's dialogue string and audio clip to dialogueTree contents that is being passed in.
                dialogueNode.nodeDialogueString    = dialogueTree.dialogueNodeElements[i].nodeDialogueString;
                dialogueNode.nodeDialogueAudioClip = dialogueTree.dialogueNodeElements[i].nodeDialogueAudioClip;

                // Check to see if the characterName needs to be changed. (By default, it should be false.)
                if (!changeCharacterName)
                {
                    dialogueNode.nodeCharacterName = characterName;
                }
                else
                {
                    dialogueNode.nodeCharacterName = dialogueTree.dialogueNodeElements[i].nodeCharacterName;
                }

                // Then add the dialogueNode so that there is always one node in the dialogueNodeElements list.
                tempDialogueTree.dialogueNodeElements.Add(dialogueNode);
            }

            Debug.LogWarning("tempDialogueTree: " + tempDialogueTree);

            // Call the DialogueManager to start the tempDialogueTree
            DialogueManager.instance.StartDialogue(tempDialogueTree);
        }
Exemplo n.º 2
0
        /// <summary>
        /// A method to initiate the dialogueTree into a displayable UI.
        /// </summary>
        /// <param nodeCharacterName="dialogueTree">The scriptable object that will be used to extract string and audioclip data for dialogue.</param>
        public void StartDialogue(DialogueTree dialogueTree)
        {
            // Set this to show that the current state of the Dialogue is being played if checking outside of the DialogueManager.
            IsDialoguePlaying = true;

            if (!dialogueTree)
            {
                EndDialogue();
                return;
            }

            if (!printDialogue && !playWithAudio)
            {
                Debug.LogError("Cannot play dialogue! The printDialogue and playWithAudio booleans are false. Mark at least one of these as true in the inspector to start the dialogue.");
                return;
            }

            if (!requireContinueButton)
            {
                autoContinueDialogueRawImage.gameObject.SetActive(true);
                autoContinueDialogueVRRawImage.gameObject.SetActive(true);
                autoContinueDialogueRawImage.GetComponent <Animator>().speed   = autoContinueDialogueImageAnimationSpeed;
                autoContinueDialogueVRRawImage.GetComponent <Animator>().speed = autoContinueDialogueImageAnimationSpeed;
            }

            // Choose to print string and play audio or just play audio without a respective string
            if (printDialogue)
            {
                // Open Dialogue Box with animation or setting local scale
                if (useOpenCloseAnimation)
                {
                    if (dialogueCanvas.transform.parent.gameObject.activeSelf)
                    {
                        dialogueCanvas.GetComponent <Animator>().enabled = true;
                        dialogueCanvas.GetComponent <Animator>().SetBool("canTransition", true);
                        dialogueCanvas.GetComponent <Animator>().SetBool("isOpen", true);
                    }
                    else if (dialogueVRCanvas.transform.parent.gameObject.activeSelf)
                    {
                        dialogueVRCanvas.GetComponent <Animator>().enabled = true;
                        dialogueVRCanvas.GetComponent <Animator>().SetBool("canTransition", true);
                        dialogueVRCanvas.GetComponent <Animator>().SetBool("isOpen", true);
                    }

                    if (openWithAnimation)
                    {
                        audioSource.PlayOneShot(openWithAnimation);
                    }
                }
                else
                {
                    if (dialogueCanvas.transform.parent.gameObject.activeSelf)
                    {
                        dialogueCanvas.GetComponent <Animator>().enabled         = false;
                        dialogueCanvas.GetComponent <RectTransform>().localScale = new Vector3(1, 1, 1);
                    }
                    else if (dialogueVRCanvas.transform.parent.gameObject.activeSelf)
                    {
                        dialogueVRCanvas.GetComponent <Animator>().enabled         = false;
                        dialogueVRCanvas.GetComponent <RectTransform>().localScale = new Vector3(1, 1, 1);
                    }

                    if (openWithoutAnimation)
                    {
                        audioSource.PlayOneShot(openWithoutAnimation);
                    }
                }
            }

            // Clear queue for new dialogue to be used.
            dialogueNodes.Clear();

            // Get the currentDialogueTree if any
            currentDialogueTree = dialogueTree;

            foreach (DialogueTree.DialogueNode node in dialogueTree.dialogueNodeElements)
            {
                dialogueNodes.Enqueue(node);
            }

            // Display First Sentence of the queues
            DisplayNextSentence();
        }