暂停功能实现

This commit is contained in:
2024-10-16 15:24:42 +08:00
parent 5bac5ba7a8
commit e869e5e43f
4 changed files with 88 additions and 34 deletions
@@ -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);
@@ -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<int> 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;
}
}
}
}
@@ -13,7 +13,7 @@ namespace AibisDream
public class DialogController : Singleton<DialogController>
{
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");
}
/// <summary>
/// 继续对话
/// </summary>
public bool TryContinueTalk()
{
// 如果对话系统在暂停状态
if (_isInPause)
{
_pauseNextStep.Invoke();
_isInPause = false;
_pauseNextStep = null;
return true;
}
// 如果对话系统不在暂停状态
return false;
}
public void PauseTalk(Action pauseNextStep)
{
_isInPause = true;
_pauseNextStep = pauseNextStep;
}
/// <summary>
/// 调用命令
/// </summary>
+22 -8
View File
@@ -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
}
}