public override void DismissLine(Action onDismissalComplete) { currentLine = null; hasPresented.Clear(); if (useFadeEffect) { StartCoroutine(Effects.FadeAlpha(canvasGroup, 1, 0, fadeOutTime, hasPresented, onDismissalComplete)); } else { canvasGroup.interactable = false; canvasGroup.alpha = 0; canvasGroup.blocksRaycasts = false; onDismissalComplete(); } }
public override void RunLine(LocalizedLine dialogueLine, Action onDialogueLineFinished) { currentLine = dialogueLine; hasPresented.Clear(); // if we have auto advance on we just hand over the completion handler // if we don't have auto advance we send over no completion handler and store the completion handler // this way it can be called later by the user action var completionHandler = autoAdvance ? onDialogueLineFinished : null; dialogueFinishedAction = onDialogueLineFinished; lineText.gameObject.SetActive(true); canvasGroup.gameObject.SetActive(true); if (continueButton != null) { continueButton.SetActive(false); } if (characterNameText == null) { if (showCharacterNameInLineView) { lineText.text = dialogueLine.Text.Text; } else { lineText.text = dialogueLine.TextWithoutCharacterName.Text; } } else { characterNameText.text = dialogueLine.CharacterName; lineText.text = dialogueLine.TextWithoutCharacterName.Text; } bool needsHold = autoAdvance && holdTime > 0; if (useFadeEffect) { if (useTypewriterEffect) { // If we're also using a typewriter effect, ensure that // there are no visible characters so that we don't // fade in on the text fully visible lineText.maxVisibleCharacters = 0; } else { // Ensure that the max visible characters is effectively unlimited. lineText.maxVisibleCharacters = int.MaxValue; } // if we are set to auto advance we want to hold for the // amount of time set in holdTime before calling the // completion handler to continue the dialogue if (needsHold) { StartCoroutine(Effects.FadeAlpha(canvasGroup, 0, 1, fadeInTime, useTypewriterEffect ? null: hasPresented, () => FadeComplete(() => HoldAndContinue(completionHandler)))); } else { // Fade up and then call FadeComplete when done StartCoroutine(Effects.FadeAlpha(canvasGroup, 0, 1, fadeInTime, useTypewriterEffect ? null: hasPresented, () => FadeComplete(completionHandler))); } } else { // Immediately appear canvasGroup.interactable = true; canvasGroup.alpha = 1; canvasGroup.blocksRaycasts = true; if (useTypewriterEffect) { if (needsHold) { StartCoroutine(Effects.Typewriter(lineText, typewriterEffectSpeed, hasPresented, OnCharacterTyped, () => HoldAndContinue(completionHandler))); } else { StartCoroutine(Effects.Typewriter(lineText, typewriterEffectSpeed, hasPresented, OnCharacterTyped, completionHandler)); } } else { if (needsHold) { Action hold = () => { hasPresented.Set(); completionHandler(); }; HoldAndContinue(hold); } else { hasPresented.Set(); completionHandler(); } } } void FadeComplete(Action onFinished) { if (useTypewriterEffect) { StartCoroutine(Effects.Typewriter(lineText, typewriterEffectSpeed, hasPresented, OnCharacterTyped, onFinished)); } else { onFinished(); } } void HoldAndContinue(Action onFinished) { StartCoroutine(DelayAction(holdTime, onFinished)); } }
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))); } }