105 lines
3.4 KiB
C#
105 lines
3.4 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using AibisDream.Framework;
|
|
using UnityEngine;
|
|
using Yarn.Unity;
|
|
|
|
namespace AibisDream
|
|
{
|
|
public class OptionView : DialogueViewBase
|
|
{
|
|
private HashSet<string> _selectedIds = new();
|
|
[SerializeField] private DefaultOptions defaultOptions;
|
|
[SerializeField] private CenterOptions centerOptions;
|
|
[SerializeField] private OnelineOptions onelineOptions;
|
|
[SerializeField] private DialogViewType defaultViewType = DialogViewType.StandardBubble;
|
|
|
|
public void LoadBubbles(BubbleSlotGroupData data)
|
|
{
|
|
defaultViewType = data.dialogViewType;
|
|
}
|
|
|
|
public override void RunOptions(DialogueOption[] dialogueOptions, Action<int> onOptionSelected)
|
|
{
|
|
EnumEventSystem.Global.Send(DialogEventEnum.OptionShow);
|
|
var options = DialogOption.GeneOptions(dialogueOptions, onOptionSelected, _selectedIds);
|
|
|
|
var viewType = GetCurrentViewType(options);
|
|
|
|
switch (viewType)
|
|
{
|
|
case DialogViewType.Default:
|
|
case DialogViewType.StandardBubble:
|
|
defaultOptions.ShowOptions(options);
|
|
break;
|
|
case DialogViewType.OnelineBox:
|
|
onelineOptions.ShowOptions(options);
|
|
break;
|
|
case DialogViewType.CenterOption:
|
|
centerOptions.ShowOptions(options);
|
|
break;
|
|
default:
|
|
Debug.Log($"选项{options[0].Character.key}没有找到选项框{viewType}");
|
|
break;
|
|
}
|
|
}
|
|
|
|
private DialogViewType GetCurrentViewType(DialogOption[] options)
|
|
{
|
|
var optionViewType = options[0].Character.dialogViewType;
|
|
|
|
if (optionViewType == DialogViewType.Default)
|
|
{
|
|
return defaultViewType;
|
|
}
|
|
|
|
return optionViewType;
|
|
}
|
|
|
|
// --------------------------- 生命周期方法 ---------------------------
|
|
|
|
private void OnEnable()
|
|
{
|
|
RegisterEvent();
|
|
}
|
|
|
|
private void OnDisable()
|
|
{
|
|
UnRegisterEvent();
|
|
}
|
|
|
|
private void RegisterEvent()
|
|
{
|
|
// 进入游戏或者进入下一个Yarn的时候清空
|
|
EnumEventSystem.Global.Register(GameLoopEnum.GameStart, ClearSelectedIds);
|
|
EnumEventSystem.Global.Register(EventEnum.NextYarn, ClearSelectedIds);
|
|
|
|
// 选择选项的时候记录
|
|
EnumEventSystem.Global.Register<DialogEventEnum, LineInfo>(DialogEventEnum.OptionSelected, RecordSelectedId);
|
|
}
|
|
|
|
private void UnRegisterEvent()
|
|
{
|
|
EnumEventSystem.Global.UnRegister(GameLoopEnum.GameStart, ClearSelectedIds);
|
|
EnumEventSystem.Global.UnRegister(EventEnum.NextYarn, ClearSelectedIds);
|
|
EnumEventSystem.Global.UnRegister<DialogEventEnum, LineInfo>(DialogEventEnum.OptionSelected, RecordSelectedId);
|
|
}
|
|
|
|
private void ClearSelectedIds()
|
|
{
|
|
_selectedIds.Clear();
|
|
}
|
|
|
|
private void RecordSelectedId(LineInfo lineInfo)
|
|
{
|
|
_selectedIds.Add(lineInfo.lineId);
|
|
}
|
|
|
|
public void HideDialog()
|
|
{
|
|
defaultOptions.HideOptions();
|
|
onelineOptions.HideOptions();
|
|
centerOptions.HideOptions();
|
|
}
|
|
}
|
|
} |