78 lines
3.1 KiB
C#
78 lines
3.1 KiB
C#
using System;
|
|
using AibisDream.Framework;
|
|
using AibisDream.Utility;
|
|
using Yarn.Unity;
|
|
using UnityEngine;
|
|
|
|
namespace AibisDream
|
|
{
|
|
public class LineView : DialogueViewBase
|
|
{
|
|
public override void RunLine(LocalizedLine dialogueLine, Action onDialogueLineFinished)
|
|
{
|
|
EnumEventSystem.Global.Send(DialogEventEnum.LineStart, DialogText.GetLine(dialogueLine));
|
|
|
|
HandleLineOutput(dialogueLine, onDialogueLineFinished);
|
|
|
|
if (DialogController.Instance.quickRunMode)
|
|
{
|
|
// 在快速模式下,延迟更多帧数并重复检查,确保选项有足够时间显示
|
|
StartCoroutine(QuickRunNextStep(onDialogueLineFinished));
|
|
}
|
|
}
|
|
|
|
private System.Collections.IEnumerator QuickRunNextStep(Action onDialogueLineFinished)
|
|
{
|
|
// 延迟1帧,给Yarn足够时间检查下一个内容是否为选项
|
|
yield return null;
|
|
|
|
// 检查1次,现在有了_isProcessingOptions标志,应该足够了
|
|
if (DialogCanvasManager.Instance.HasActiveOptions())
|
|
{
|
|
yield break;
|
|
}
|
|
|
|
// 再等1帧确保
|
|
yield return null;
|
|
|
|
// 如果没有选项,则跳过到下一行
|
|
if (!DialogCanvasManager.Instance.HasActiveOptions())
|
|
{
|
|
DialogCanvasManager.Instance.TrySkipLine(true);
|
|
DialogCanvasManager.Instance.NextStep();
|
|
}
|
|
}
|
|
|
|
private void HandleLineOutput(LocalizedLine dialogueLine, Action onDialogueLineFinished)
|
|
{
|
|
DialogCanvasManager.Instance.ShowLine(dialogueLine.TextWithoutCharacterName.Text,
|
|
dialogueLine.GetCharacterVo(), onDialogueLineFinished, dialogueLine.TextID, dialogueLine.IsAutoSkipLine());
|
|
}
|
|
|
|
public override void RunOptions(DialogueOption[] dialogueOptions, Action<int> onOptionSelected)
|
|
{
|
|
EnumEventSystem.Global.Send(DialogEventEnum.OptionShow);
|
|
|
|
// 自动暂停快进,选项被选择后再恢复
|
|
bool wasQuickRun = DialogController.Instance.quickRunMode;
|
|
DialogController.Instance.quickRunMode = false;
|
|
|
|
// 包装原有回调,选项被选择后恢复快进状态
|
|
Action<int> wrappedOnOptionSelected = idx => {
|
|
// 延迟一帧恢复快进状态,确保Yarn流程正确执行
|
|
DialogController.Instance.StartCoroutine(RestoreQuickRunMode(wasQuickRun));
|
|
onOptionSelected(idx);
|
|
};
|
|
|
|
// 只调用一次ShowOptions,使用包装后的回调
|
|
var options = DialogOption.GeneOptions(dialogueOptions, wrappedOnOptionSelected);
|
|
DialogCanvasManager.Instance.ShowOptions(options);
|
|
}
|
|
|
|
private System.Collections.IEnumerator RestoreQuickRunMode(bool wasQuickRun)
|
|
{
|
|
yield return null; // 等待一帧
|
|
DialogController.Instance.quickRunMode = wasQuickRun;
|
|
}
|
|
}
|
|
} |