/// <summary> /// Shows the next dialogue line if there is any and option buttons if we hit the end of dialogue. /// </summary> private void ShowNextDialogueLine() { if (lines.Count == 0) { Debug.LogWarning("There is no dialogue line left!"); return; } DialogueLine dl = lines.Dequeue(); SetDialogueWindow(dl); if (dl.actions != null) { ExecuteAllDialogueActions(dl.actions); } if (lines.Count != 0) { nextButton.SetActive(true); } //we are at the end of the dialogue, shows options else { nextButton.SetActive(false); if (currentDialogue.dialogueOptions == null || currentDialogue.dialogueOptions.Length == 0) { ConversationEnded?.Invoke(); return; } //show each option in dialogue for (int i = 0; i < currentDialogue.dialogueOptions.Length; i++) { DialogueOption opt = currentDialogue.dialogueOptions[i]; if (opt.prerequisities != null && !DoesMeetPrerequisities(opt.prerequisities)) { continue; } GameObject go = Instantiate(dialogueOptionPrefab) as GameObject; go.transform.SetParent(dialogueWindow, false); DialogueOptionButton button = go.gameObject.GetComponent <DialogueOptionButton>(); button.dialogueOptionID = i; button.optionText.text = opt.optionText; optionButtons.Add(go); } } }
/// <summary> /// When user clicks option button, execute all choice actions and then prepares new dialogue if there is any /// </summary> /// <param name="id">position of the choice in the array</param> private void OnDialogueOptionClicked(int id) { for (int i = optionButtons.Count - 1; i >= 0; i--) { Destroy(optionButtons[i]); } optionButtons.Clear(); DialogueOption option = currentDialogue.dialogueOptions[id]; if (option.actions != null) { ExecuteAllDialogueActions(option.actions); } if (option.subsequentDialogue != null) { currentDialogue = option.subsequentDialogue; PrepareNextDialogues(); ShowNextDialogueLine(); } }