暂停功能实现
This commit is contained in:
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user