66 lines
1.9 KiB
C#
66 lines
1.9 KiB
C#
using System;
|
|
using System.Linq;
|
|
using AibisDream.Framework;
|
|
using AibisDream.Kit;
|
|
using AibisDream.Utility;
|
|
using UnityEngine;
|
|
using Yarn.Unity;
|
|
|
|
namespace AibisDream
|
|
{
|
|
public interface IDialogView
|
|
{
|
|
public void ShowLine(string dialogLine, CharacterVo character, Action nextStep, Action onTextShowed = null,
|
|
bool isAutoSkip = false);
|
|
|
|
public void ShowOptions(DialogOption[] dialogueOptions);
|
|
|
|
public void HideDialog();
|
|
|
|
public bool TrySkipLine();
|
|
|
|
public void NextStep();
|
|
}
|
|
|
|
public struct DialogOption
|
|
{
|
|
private Action<int> _onOptionSelected;
|
|
private DialogueOption _option;
|
|
|
|
public bool IsAvailable => _option.IsAvailable;
|
|
public string Line => _option.Line.TextWithoutCharacterName.Text;
|
|
public CharacterVo Character => _option.Line.GetCharacterVo();
|
|
|
|
/// <summary>
|
|
/// 选择该选项
|
|
/// </summary>
|
|
public void Select()
|
|
{
|
|
if (!_option.IsAvailable)
|
|
{
|
|
Debug.Log($"{_option.Line} 不可用");
|
|
return;
|
|
}
|
|
|
|
EnumEventSystem.Global.Send(DialogEventEnum.OptionSelected, TransToLine());
|
|
_onOptionSelected.Invoke(_option.DialogueOptionID);
|
|
}
|
|
|
|
private DialogText TransToLine()
|
|
{
|
|
return new DialogText
|
|
{
|
|
isOption = true,
|
|
lineId = _option.TextID,
|
|
line = _option.Line.TextWithoutCharacterName.Text,
|
|
actor = _option.Line.GetCharacterVo()
|
|
};
|
|
}
|
|
|
|
public static DialogOption[] GeneOptions(DialogueOption[] dialogueOptions, Action<int> onOptionSelected)
|
|
{
|
|
return dialogueOptions
|
|
.Select(item => new DialogOption { _option = item, _onOptionSelected = onOptionSelected }).ToArray();
|
|
}
|
|
}
|
|
} |