public override void RunOptions(DialogueOption[] dialogueOptions, Action <int> onOptionSelected) { // Hide all existing option views foreach (var optionView in optionViews) { optionView.gameObject.SetActive(false); } // If we don't already have enough option views, create more while (dialogueOptions.Length > optionViews.Count) { var optionView = CreateNewOptionView(); optionView.gameObject.SetActive(false); } // Set up all of the option views int optionViewsCreated = 0; for (int i = 0; i < dialogueOptions.Length; i++) { var optionView = optionViews[i]; var option = dialogueOptions[i]; if (option.IsAvailable == false && showUnavailableOptions == false) { // Don't show this option. continue; } optionView.gameObject.SetActive(true); optionView.Option = option; // The first available option is selected by default if (optionViewsCreated == 0) { optionView.Select(); } optionViewsCreated += 1; } // Update the last line, if one is configured if (lastLineText != null) { if (lastSeenLine != null) { lastLineText.gameObject.SetActive(true); lastLineText.text = lastSeenLine.Text.Text; } else { lastLineText.gameObject.SetActive(false); } } // Note the delegate to call when an option is selected OnOptionSelected = onOptionSelected; // Fade it all in StartCoroutine(Effects.FadeAlpha(canvasGroup, 0, 1, fadeTime)); /// <summary> /// Creates and configures a new <see cref="OptionView"/>, and adds /// it to <see cref="optionViews"/>. /// </summary> OptionView CreateNewOptionView() { var optionView = Instantiate(optionViewPrefab); optionView.transform.SetParent(transform, false); optionView.transform.SetAsLastSibling(); optionView.OnOptionSelected = OptionViewWasSelected; optionViews.Add(optionView); return(optionView); } /// <summary> /// Called by <see cref="OptionView"/> objects. /// </summary> void OptionViewWasSelected(DialogueOption option) { StartCoroutine(Effects.FadeAlpha(canvasGroup, 1, 0, fadeTime, null, () => OnOptionSelected(option.DialogueOptionID))); } }