using System; using AibisDream.Utility; using Yarn.Unity; namespace AibisDream { public class CommandOptionView : DialogueViewBase { // 进入指令选项模式 private bool _waitCommandOptions; private string _commandName; 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: // 获取选项名称 dialogueLine.Text.TryGetPauseCommandAttr(out var pauseCommandName); // 传递暂停指令 var step = YarnContinueStep.GeneContinueStep(onDialogueLineFinished); DialogController.Instance.InvokePauseCommand(pauseCommandName, step); break; case CommandLineType.OptionCommand: // 选项指令 _waitCommandOptions = true; dialogueLine.Text.TryGetOptionCommandAttr(out var curCommandName); // 保存指令 _commandName = curCommandName; // 进入下一步 onDialogueLineFinished.Invoke(); break; case CommandLineType.NonCommand: default: // 非Command直接跳过 _waitCommandOptions = false; base.RunLine(dialogueLine, onDialogueLineFinished); break; } } } }