90 lines
2.7 KiB
C#
90 lines
2.7 KiB
C#
using AibisDream.Framework;
|
|
using AibisDream.Kit;
|
|
using AibisDream.UI;
|
|
using UnityEngine;
|
|
|
|
namespace AibisDream
|
|
{
|
|
public class DialogUIManager : Singleton<DialogUIManager>
|
|
{
|
|
private CanvasGroup _canvasGroup;
|
|
|
|
[SerializeField] private LineRunner lineView;
|
|
[SerializeField] private OptionView optionView;
|
|
|
|
public override void OnSingletonInit()
|
|
{
|
|
_canvasGroup = GetComponent<CanvasGroup>();
|
|
|
|
EnumEventSystem.Global.Register<DialogEventEnum, LineInfo>(DialogEventEnum.LineStart, AddDialogueLine);
|
|
EnumEventSystem.Global.Register<DialogEventEnum, LineInfo>(DialogEventEnum.OptionSelected, AddDialogueLine);
|
|
EnumEventSystem.Global.Register(EventEnum.NextYarn, CleanDialogHistory);
|
|
EnumEventSystem.Global.Register(GameLoopEnum.GameQuit, CleanDialogHistory);
|
|
}
|
|
|
|
public override void OnSingletonDestroy()
|
|
{
|
|
EnumEventSystem.Global.UnRegister<DialogEventEnum, LineInfo>(DialogEventEnum.LineStart, AddDialogueLine);
|
|
EnumEventSystem.Global.UnRegister<DialogEventEnum, LineInfo>(DialogEventEnum.OptionSelected, AddDialogueLine);
|
|
EnumEventSystem.Global.UnRegister(EventEnum.NextYarn, CleanDialogHistory);
|
|
EnumEventSystem.Global.UnRegister(GameLoopEnum.GameQuit, CleanDialogHistory);
|
|
}
|
|
|
|
private RecordPanel RecordPanel => UIManager.Instance.GetPanel<RecordPanel>();
|
|
|
|
/// <summary>
|
|
/// 记录对话
|
|
/// </summary>
|
|
/// <param name="line">对话</param>
|
|
private void AddDialogueLine(LineInfo line)
|
|
{
|
|
if (line.character.dialogViewType == DialogViewType.Task)
|
|
{
|
|
return;
|
|
}
|
|
|
|
RecordPanel.AppendDialogLine(line);
|
|
}
|
|
|
|
private void CleanDialogHistory()
|
|
{
|
|
RecordPanel.ClearDialog();
|
|
}
|
|
|
|
public void CloseCanvas()
|
|
{
|
|
gameObject.SetActive(false);
|
|
}
|
|
|
|
public void OpenCanvas()
|
|
{
|
|
gameObject.SetActive(true);
|
|
}
|
|
|
|
public void HideDialog()
|
|
{
|
|
// 关闭所有对话框
|
|
BubbleGroup.Instance.HideDialog();
|
|
}
|
|
|
|
public void RegisterScreenView(DialogViewType dialogViewType, ILineView screenView)
|
|
{
|
|
lineView.RegisterView(dialogViewType, screenView);
|
|
}
|
|
|
|
public void UnRegisterScreenView(DialogViewType dialogViewType)
|
|
{
|
|
lineView.UnRegisterView(dialogViewType);
|
|
}
|
|
}
|
|
|
|
public enum DialogViewType
|
|
{
|
|
Default,
|
|
Screen,
|
|
CenterText,
|
|
CenterOption,
|
|
Task,
|
|
StandardBubble
|
|
}
|
|
} |