using System; using AibisDream.Utility; using Yarn.Unity; namespace AibisDream { public class CommandOptionView : DialogueViewBase { // 进入指令选项模式 private bool _waitCommandOptions; private string _commandName; // 进入暂停后 private bool _isInPause; private Action _pauseNextStep; public override void RunLine(LocalizedLine dialogueLine, Action onDialogueLineFinished) { ProcessCommandLine(dialogueLine, onDialogueLineFinished); } public override void RunOptions(DialogueOption[] dialogueOptions, Action onOptionSelected) { // 非指令直接跳过 if (!_waitCommandOptions) { base.RunOptions(dialogueOptions, onOptionSelected); return; } DialogController.Instance.IsTalking = false; // 传输选项 YarnOption[] options = YarnOption.GeneOptions(dialogueOptions, onOptionSelected); DialogController.Instance.InvokeOptionCommand(_commandName, options); } public override void InterruptLine(LocalizedLine dialogueLine, Action onDialogueLineFinished) { base.InterruptLine(dialogueLine, onDialogueLineFinished); } public override void DismissLine(Action onDismissalComplete) { base.DismissLine(onDismissalComplete); } public override void UserRequestedViewAdvancement() { base.UserRequestedViewAdvancement(); } private void ProcessCommandLine(LocalizedLine dialogueLine, Action onDialogueLineFinished) { // 判断当前行是否是Command行,否则直接跳过 CommandLineType commandLineType = dialogueLine.Text.MatchCommandType(); // 分情况处理 switch (commandLineType) { case CommandLineType.Pause: DialogController.Instance.PauseTalk(onDialogueLineFinished); break; case CommandLineType.OptionCommand: // 选项指令 _waitCommandOptions = true; dialogueLine.Text.TryGetCommandAttr(out var curCommandName); // 保存指令 _commandName = curCommandName; // 进入下一步 onDialogueLineFinished.Invoke(); break; case CommandLineType.NonCommand: default: // 非Command直接跳过 base.RunLine(dialogueLine, onDialogueLineFinished); break; } } } }