private void RunChoiceDialogue(ChoiceDialogue choiceDialogue) { // Clear the choices menu foreach (Transform child in choicePanelContainer.transform) { GameObject.Destroy(child.gameObject); } // Add new choices to the menu int numberOfChoices = choiceDialogue.choices.Length; for (int i = 0; i < numberOfChoices; i++) { GameObject choiceBox = Instantiate(choicePrefab, new Vector3(0, 0, 0), Quaternion.identity, choicePanelContainer.transform) as GameObject; Text choiceText = choiceBox.GetComponent <Text>(); choiceText.text = choiceDialogue.choicesText[i]; ChoiceSelector choiceOnClick = choiceBox.GetComponent <ChoiceSelector>(); // Capture the value of i for the lambda int currentI = i; choiceOnClick.SelectThisChoice += () => { choicePanel.SetActive(false); // Assume choice box is never last currentDialogue = choiceDialogue.choices[currentI]; RunCurrentDialogue(); }; } choicePanel.SetActive(true); }
// A manually constructed Dialogue tree for testing public static Dialogue GetTestDialogue() { Dialogue endHappy = new PlainDialogue(true, 0, "I'm great, thank you!"); Dialogue endRude = new PlainDialogue(true, 0, "Keep quiet! Silence in the restaurant please."); Dialogue choice = new ChoiceDialogue(new Dialogue[] { endHappy, endRude }, new string[] { "Great (Happy)", "Keep quiet (Rude)" }); Dialogue initial = new PlainDialogue(false, 1, "How are you today?", choice); return(initial); }
public void LoadChoiceDialogue(ChoiceDialogue db) { _choiceList.Clear(); _msgTitle = null; tempchoicedb = null; List <string> s = db.ChoiceMsgList; if (s.Count >= 1) { _msgTitle = db.dialogueTitle; for (int i = 0; i < s.Count; i++) { _choiceList.Add(s[i]); } tempchoicedb = db; } }
// Checks what kind of dialogue it is and calls the correct function. // Returns the next dialogue, or null, if it is the last dialogue. private void RunCurrentDialogue() { if (currentDialogue.isPlain) { PlainDialogue plain = (PlainDialogue)currentDialogue; if (plain.isPlayer) { RunMeDialogue(plain); } else { RunTheyDialogue(plain); } } else { ChoiceDialogue choice = (ChoiceDialogue)currentDialogue; RunChoiceDialogue(choice); } }