private void HandleChoiceNode(ChoiceNode choiceNode) { if (choiceNode == null) { return; } _currentChoiceNode = choiceNode; _waiting = true; _normalSubtitlesObject.SetActive(false); _choicesObject.SetActive(true); _choiceSubtitleText.gameObject.SetActive(true); var branches = choiceNode.GetAvailableBranches(); for (int i = 0; i < branches.Count; i++) { Branch branch = branches[i]; GameObject choiceButton = Instantiate(_choiceButtonPrefab, _choiceContent); //Assign text to the button that can be clicked in the format of // "1. Option to pick" Text text = choiceButton.GetComponentInChildren <Text>(); if (text != null) { //Regex Magic - stolen from StackOverflow //string choiceText = Regex.Match(_previousDialogueNode.Text, @"\[([^]]*)\]").Groups[1].Value; string choiceText = branch.DialogueNode.Text; if (choiceText.StartsWith("[")) { string[] groups = choiceText.Split('[', ']', '\n', '\t'); if (groups.Length >= 4) { choiceText = groups[1]; } } text.text = string.Format("{0}. {1}", i + 1, choiceText); } //Assign click command Button button = choiceButton.GetComponentInChildren <Button>(); if (button == null) { continue; } int capturedIndex = i; button.onClick.AddListener(() => { PickBranch(choiceNode, capturedIndex); }); } if (_previousDialogueNode != null) { _choiceSubtitleText.text = _previousDialogueNode.Text; } }
private void PickBranch(ChoiceNode choiceNode, int index) { choiceNode.PickBranch(choiceNode.GetAvailableBranches()[index]); DestroyBranchObjects(); _waiting = false; }