Esempio n. 1
0
    public IEnumerator DisplayText(string[] lines, OnDialogFinish onFinish = null)
    {
        gameObject.SetActive(true);
        dialogTextPanel.SetActive(true);
        Text dialogText = dialogTextPanel.GetComponentInChildren <Text>();
        int  lineIndex  = 0;

        while (lineIndex < lines.Length)
        {
            int charIndex = 0;
            while (charIndex < lines[lineIndex].Length)
            {
                dialogText.text = lines[lineIndex].Substring(0, charIndex + 1);
                charIndex++;
                yield return(new WaitForSeconds(secondsBetweenChar));
            }
            // done a line, wait for user input to continue
            bool next = false;
            while (!next)
            {
                if (Input.GetKeyUp("space"))
                {
                    next = true;
                }
                yield return(null);
            }
            lineIndex++;
        }
        dialogTextPanel.SetActive(false);
        gameObject.SetActive(false);
        if (onFinish != null)
        {
            onFinish();
        }
    }
Esempio n. 2
0
    IEnumerator EndDialog()
    {
        dialogBoxAnimator.SetBool("Start", false);
        yield return(new WaitForSeconds(dialogBoxAnimator.GetCurrentAnimatorStateInfo(0).length));

        _currentDialogue.OnDialogEndEvent.Invoke();
        OnDialogFinish?.Invoke(this, null);
        isDialogPlaying = false;
    }
Esempio n. 3
0
    public IEnumerator Talk(MemoryList memoryList, DialogDisplay dialogBox, OnDialogFinish onDialogFinish)
    {
        bool keepTalking = true;

        while (keepTalking)
        {
            if (node == null)
            {
                keepTalking = false;
            }
            else if (node is DialogTextNode)
            {
                DialogTextNode textNode = (DialogTextNode)node;
                if (textNode.requireItems == null || memoryList.Contains(textNode.requireItems))
                {
                    yield return(dialogBox.DisplayText(textNode.dialogs));

                    if (textNode.addItems != null)
                    {
                        foreach (string item in textNode.addItems)
                        {
                            memoryList.AddItem(item);
                        }
                    }
                    if (node.children != null)
                    {
                        node = node.children[0];
                        if (node.id == 999)
                        {
                            GameObject.FindGameObjectWithTag("GameController").GetComponent <GameManager>().GameEnd();
                            onDialogFinish();
                            yield break;
                        }
                    }
                    else
                    {
                        node = null;
                    }
                }
                else
                {
                    yield return(dialogBox.DisplayText(new string[] { "Hi Ben!" }));
                }
                keepTalking = false;
            }
            else if (node is DialogOptionNode)
            {
                DialogOptionNode optionNode       = (DialogOptionNode)node;
                string[]         availableOptions = optionNode.options
                                                    .Where((option) => !option.selected && (option.requireItems == null || memoryList.Contains(option.requireItems)))
                                                    .Select((option) => option.text).ToArray();

                if (availableOptions.Length > 0)
                {
                    yield return(dialogBox.DisplayOptionList(availableOptions, (selection) => {
                        node = optionNode.Select(selection);
                    }));

                    if (optionNode == node)
                    {
                        keepTalking = false;
                    }
                }
                else
                {
                    yield return(dialogBox.DisplayText(new string[] { "Hi Ben!" }));

                    keepTalking = false;
                }
            }
            yield return(null);
        }
        onDialogFinish();
    }