From e869e5e43f295bcc84e2a718c352abe988396d42 Mon Sep 17 00:00:00 2001 From: Ding Yuntian <1491671119@qq.com> Date: Wed, 16 Oct 2024 15:24:42 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9A=82=E5=81=9C=E5=8A=9F=E8=83=BD=E5=AE=9E?= =?UTF-8?q?=E7=8E=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Assets/Scripts/Dialog System/AudioView.cs | 2 - .../Dialog System/CommandOptionView.cs | 60 ++++++++++++------- .../Scripts/Dialog System/DialogController.cs | 30 +++++++++- Assets/Scripts/Utility/YarnUtil.cs | 30 +++++++--- 4 files changed, 88 insertions(+), 34 deletions(-) diff --git a/Assets/Scripts/Dialog System/AudioView.cs b/Assets/Scripts/Dialog System/AudioView.cs index e96ab6292..8e84eb7f9 100644 --- a/Assets/Scripts/Dialog System/AudioView.cs +++ b/Assets/Scripts/Dialog System/AudioView.cs @@ -1,6 +1,5 @@ using System; using AibisDream.Utility; -using UnityEngine; using Yarn.Unity; namespace AibisDream @@ -10,7 +9,6 @@ namespace AibisDream public override void RunLine(LocalizedLine dialogueLine, Action onDialogueLineFinished) { var voicePath = dialogueLine.GetCharacterVo().voicePath; - Debug.Log(voicePath); if (!string.IsNullOrWhiteSpace(voicePath)) { AudioManager.Instance.RandomPlayVoice(voicePath); diff --git a/Assets/Scripts/Dialog System/CommandOptionView.cs b/Assets/Scripts/Dialog System/CommandOptionView.cs index 01d8d8bae..b013d5b1b 100644 --- a/Assets/Scripts/Dialog System/CommandOptionView.cs +++ b/Assets/Scripts/Dialog System/CommandOptionView.cs @@ -1,4 +1,4 @@ -using System; + using System; using AibisDream.Utility; using Yarn.Unity; @@ -7,37 +7,22 @@ namespace AibisDream public class CommandOptionView : DialogueViewBase { // 进入指令选项模式 - private bool _isInCommand; + private bool _waitCommandOptions; private string _commandName; + + // 进入暂停后 + private bool _isInPause; + private Action _pauseNextStep; public override void RunLine(LocalizedLine dialogueLine, Action onDialogueLineFinished) { - // 判断选项选项行 - if (dialogueLine.Text.IsOptionAttrLine()) - { - _isInCommand = true; - base.RunLine(dialogueLine, onDialogueLineFinished); - return; - } - // 判断是否进入Command状态 - _isInCommand = dialogueLine.Text.TryGetCommandAttr(out var curCommandName); - if (_isInCommand) - { - // 保存指令 - _commandName = curCommandName; - // 进入下一步 - onDialogueLineFinished.Invoke(); - } - else - { - base.RunLine(dialogueLine, onDialogueLineFinished); - } + ProcessCommandLine(dialogueLine, onDialogueLineFinished); } public override void RunOptions(DialogueOption[] dialogueOptions, Action onOptionSelected) { // 非指令直接跳过 - if (!_isInCommand) + if (!_waitCommandOptions) { base.RunOptions(dialogueOptions, onOptionSelected); return; @@ -63,6 +48,35 @@ namespace AibisDream { 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; + } + } } } diff --git a/Assets/Scripts/Dialog System/DialogController.cs b/Assets/Scripts/Dialog System/DialogController.cs index 008aa1ddd..21a88b2a0 100644 --- a/Assets/Scripts/Dialog System/DialogController.cs +++ b/Assets/Scripts/Dialog System/DialogController.cs @@ -13,7 +13,7 @@ namespace AibisDream public class DialogController : Singleton { private const string BookManager = "BookManager"; - + private DialogueRunner dialogueRunner; private VariableStorageBehaviour _variableStorage; @@ -45,6 +45,10 @@ namespace AibisDream public bool IsBlock { get; private set; } public bool quickRunMode; + + // 暂停对话 + private bool _isInPause; + private Action _pauseNextStep; # endregion @@ -108,6 +112,30 @@ namespace AibisDream dialogueRunner.StartDialogue("Start"); } + /// + /// 继续对话 + /// + public bool TryContinueTalk() + { + // 如果对话系统在暂停状态 + if (_isInPause) + { + _pauseNextStep.Invoke(); + _isInPause = false; + _pauseNextStep = null; + return true; + } + + // 如果对话系统不在暂停状态 + return false; + } + + public void PauseTalk(Action pauseNextStep) + { + _isInPause = true; + _pauseNextStep = pauseNextStep; + } + /// /// 调用命令 /// diff --git a/Assets/Scripts/Utility/YarnUtil.cs b/Assets/Scripts/Utility/YarnUtil.cs index b16e3ab18..894ab1aa0 100644 --- a/Assets/Scripts/Utility/YarnUtil.cs +++ b/Assets/Scripts/Utility/YarnUtil.cs @@ -12,7 +12,7 @@ namespace AibisDream.Utility { private const string CommandAttr = "command"; - private const string OptionAttr = "options"; + private const string PauseAttr = "pause"; private const string CommandProp = "name"; @@ -20,8 +20,22 @@ namespace AibisDream.Utility public static bool HasCommandAttr(this MarkupParseResult text) { - return text.TryGetAttributeWithName(CommandAttr, out var attribute1) || - text.TryGetAttributeWithName(OptionAttr, out var attribute2); + return MatchCommandType(text) != CommandLineType.NonCommand; + } + + public static CommandLineType MatchCommandType(this MarkupParseResult text) + { + if (text.TryGetAttributeWithName(CommandAttr, out var attribute1)) + { + return CommandLineType.OptionCommand; + } + + if (text.TryGetAttributeWithName(PauseAttr, out var attribute2)) + { + return CommandLineType.Pause; + } + + return CommandLineType.NonCommand; } public static bool TryGetCommandAttr(this MarkupParseResult text, out string commandName) @@ -30,11 +44,6 @@ namespace AibisDream.Utility commandName = res ? attribute.Properties[CommandProp].StringValue : null; return res; } - - public static bool IsOptionAttrLine(this MarkupParseResult text) - { - return text.TryGetAttributeWithName(OptionAttr, out var outStr); - } public static void AddCommandListener(this DialogueRunner runner, CommandHandler onCommand) { @@ -129,4 +138,9 @@ namespace AibisDream.Utility #endregion } + + public enum CommandLineType + { + OptionCommand, Pause, NonCommand + } } \ No newline at end of file