89 lines
2.7 KiB
C#
89 lines
2.7 KiB
C#
using System;
|
|
using AibisDream.Framework;
|
|
using AibisDream.Utility;
|
|
using Yarn.Unity;
|
|
|
|
namespace AibisDream
|
|
{
|
|
public class LineView : DialogueViewBase
|
|
{
|
|
// 进入指令选项模式
|
|
private bool _isInCommand;
|
|
|
|
public override void RunLine(LocalizedLine dialogueLine, Action onDialogueLineFinished)
|
|
{
|
|
_isInCommand = dialogueLine.Text.HasCommandAttr();
|
|
|
|
if (_isInCommand)
|
|
{
|
|
DialogCanvasManager.GetCurView().HideDialog();
|
|
base.RunLine(dialogueLine, onDialogueLineFinished);
|
|
return;
|
|
}
|
|
|
|
EnumEventSystem.Global.Send(EventEnum.DialogLine, DialogLine.GetLine(dialogueLine));
|
|
|
|
Action jumpVoice = SkipVoice;
|
|
HandleLineOutput(dialogueLine, jumpVoice, onDialogueLineFinished);
|
|
HandleVoiceOutput(dialogueLine);
|
|
|
|
if (DialogController.Instance.quickRunMode)
|
|
{
|
|
onDialogueLineFinished.Invoke();
|
|
}
|
|
}
|
|
|
|
private void HandleLineOutput(LocalizedLine dialogueLine, Action onTextShowed, Action onDialogueLineFinished)
|
|
{
|
|
DialogCanvasManager.GetCurView().ShowLine(dialogueLine.TextWithoutCharacterName.Text,
|
|
dialogueLine.GetCharacterVo(), onDialogueLineFinished, onTextShowed, dialogueLine.IsAutoSkipLine());
|
|
}
|
|
|
|
private void HandleVoiceOutput(LocalizedLine dialogueLine)
|
|
{
|
|
// 播放语音
|
|
var voicePath = dialogueLine.GetCharacterVo().voicePath;
|
|
if (!string.IsNullOrWhiteSpace(voicePath))
|
|
{
|
|
AudioManager.Instance.RandomPlayVoice(voicePath);
|
|
}
|
|
}
|
|
|
|
private void SkipVoice()
|
|
{
|
|
AudioManager.Instance.StopVoice();
|
|
}
|
|
|
|
public override void RunOptions(DialogueOption[] dialogueOptions, Action<int> onOptionSelected)
|
|
{
|
|
if (_isInCommand)
|
|
{
|
|
DialogCanvasManager.GetCurView().HideDialog();
|
|
base.RunOptions(dialogueOptions, onOptionSelected);
|
|
return;
|
|
}
|
|
|
|
var options = DialogOption.GeneOptions(dialogueOptions, onOptionSelected);
|
|
DialogCanvasManager.GetCurView().ShowOptions(options);
|
|
}
|
|
|
|
public override void UserRequestedViewAdvancement()
|
|
{
|
|
if (_isInCommand)
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (DialogController.Instance.IsBlock)
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (!DialogCanvasManager.GetCurView().TrySkipLine())
|
|
{
|
|
AudioManager.Instance.StopVoice();
|
|
requestInterrupt?.Invoke();
|
|
}
|
|
}
|
|
}
|
|
} |