110 lines
2.9 KiB
C#
110 lines
2.9 KiB
C#
using System;
|
|
using UnityEngine;
|
|
using Yarn.Unity;
|
|
|
|
namespace AibisDream
|
|
{
|
|
public class YarnOption
|
|
{
|
|
private int _idx;
|
|
|
|
private readonly DialogueOption _dialogueOption;
|
|
|
|
private Action<int> _onOptionSelected;
|
|
|
|
/// <summary>
|
|
/// 选项中的文字
|
|
/// </summary>
|
|
public string Text => _dialogueOption.Line.TextWithoutCharacterName.Text;
|
|
|
|
public bool IsAvailable => _dialogueOption.IsAvailable;
|
|
|
|
public int Index => _idx;
|
|
|
|
public YarnOption(int idx, DialogueOption dialogueOption, Action<int> onOptionSelected)
|
|
{
|
|
_dialogueOption = dialogueOption;
|
|
_onOptionSelected = onOptionSelected;
|
|
_idx = idx;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 选择该选项
|
|
/// </summary>
|
|
public void SelectOption()
|
|
{
|
|
if (!IsAvailable)
|
|
{
|
|
Debug.LogWarning($"选项 {Text} 不可用");
|
|
return;
|
|
}
|
|
|
|
if (_onOptionSelected == null)
|
|
{
|
|
Debug.LogWarning($"选项 {Text} 已经执行过了");
|
|
return;
|
|
}
|
|
|
|
// 执行选项
|
|
_onOptionSelected.Invoke(_dialogueOption.DialogueOptionID);
|
|
_onOptionSelected = null;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 生成选项
|
|
/// </summary>
|
|
/// <param name="options">原始选项</param>
|
|
/// <param name="onOptionSelected">选择</param>
|
|
/// <returns>包装选项</returns>
|
|
public static YarnOption[] GeneOptions(DialogueOption[] options, Action<int> onOptionSelected)
|
|
{
|
|
var yarnOptions = new YarnOption[options.Length];
|
|
for (var i = 0; i < options.Length; i++)
|
|
{
|
|
yarnOptions[i] = new YarnOption(i, options[i], onOptionSelected);
|
|
}
|
|
|
|
return yarnOptions;
|
|
}
|
|
}
|
|
|
|
public class YarnContinueStep
|
|
{
|
|
private Action _nextStep;
|
|
|
|
public YarnContinueStep(Action nextStep)
|
|
{
|
|
_nextStep = nextStep;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 继续对话
|
|
/// </summary>
|
|
public void ContinueTalk()
|
|
{
|
|
if (_nextStep != null)
|
|
{
|
|
_nextStep.Invoke();
|
|
DialogController.Instance.isInPause = false;
|
|
_nextStep = null;
|
|
}
|
|
else
|
|
{
|
|
Debug.LogWarning("对话已经继续,请勿重复触发");
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 生成继续命令
|
|
/// </summary>
|
|
/// <param name="nextStep">下一句命令</param>
|
|
/// <returns>命令</returns>
|
|
public static YarnContinueStep GeneContinueStep(Action nextStep)
|
|
{
|
|
DialogController.Instance.isInPause = true;
|
|
return new YarnContinueStep(nextStep);
|
|
}
|
|
}
|
|
}
|
|
|