screen
This commit is contained in:
@@ -8,40 +8,40 @@ using UnityEngine.UI;
|
||||
|
||||
namespace AibisDream
|
||||
{
|
||||
public class DialogCanvasManager : Singleton<DialogCanvasManager>
|
||||
public class DialogCanvasManager : Singleton<DialogCanvasManager>, IDialogView
|
||||
{
|
||||
private const string BubbleView = "Dialog Bubble View";
|
||||
private const string OldBoxView = "Dialog Box";
|
||||
|
||||
private const string QuickTalk = "Quick Talk";
|
||||
|
||||
#region 引用
|
||||
|
||||
private IDialogView _bubbleView;
|
||||
private IDialogView _oldBoxView;
|
||||
|
||||
private readonly Dictionary<DialogViewType, IDialogView> _dialogViewDict = new();
|
||||
private IDialogView _curView;
|
||||
|
||||
private IDialogView _lastShowView;
|
||||
private GameObject _quickTalkButton;
|
||||
|
||||
#endregion
|
||||
|
||||
private List<IUnRegister> _rmvList = new();
|
||||
|
||||
private readonly List<IUnRegister> _rmvList = new();
|
||||
|
||||
public override void OnSingletonInit()
|
||||
{
|
||||
InitDialogViews();
|
||||
InitQuickTalkButton();
|
||||
InitEvent();
|
||||
// 默认为旧Box
|
||||
_curView = _bubbleView;
|
||||
}
|
||||
|
||||
private void Start()
|
||||
{
|
||||
_curView = _dialogViewDict[DialogViewType.OldBox];
|
||||
}
|
||||
|
||||
private void InitEvent()
|
||||
{
|
||||
_rmvList.Add(EnumEventSystem.Global.Register<DialogEventEnum, DialogLine>(DialogEventEnum.LineStart, AddDialogueLine));
|
||||
_rmvList.Add(EnumEventSystem.Global.Register<DialogEventEnum, DialogLine>(DialogEventEnum.OptionSelected, AddDialogueLine));
|
||||
_rmvList.Add(
|
||||
EnumEventSystem.Global.Register<DialogEventEnum, DialogText>(DialogEventEnum.LineStart,
|
||||
AddDialogueLine));
|
||||
_rmvList.Add(
|
||||
EnumEventSystem.Global.Register<DialogEventEnum, DialogText>(DialogEventEnum.OptionSelected,
|
||||
AddDialogueLine));
|
||||
_rmvList.Add(EnumEventSystem.Global.Register(EventEnum.NextYarn, CleanDialogHistory));
|
||||
}
|
||||
|
||||
@@ -63,11 +63,6 @@ namespace AibisDream
|
||||
DialogController.OnDialogueComplete -= HideDialog;
|
||||
}
|
||||
|
||||
private void HideDialog()
|
||||
{
|
||||
_curView.HideDialog();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private void Update()
|
||||
@@ -80,15 +75,6 @@ namespace AibisDream
|
||||
|
||||
#region 对话框相关处理
|
||||
|
||||
private void InitDialogViews()
|
||||
{
|
||||
_bubbleView = transform.Find(BubbleView).GetComponent<IDialogView>();
|
||||
_oldBoxView = transform.Find(OldBoxView).GetComponent<IDialogView>();
|
||||
|
||||
_bubbleView.HideDialog();
|
||||
_oldBoxView.HideDialog();
|
||||
}
|
||||
|
||||
private void InitQuickTalkButton()
|
||||
{
|
||||
_quickTalkButton = transform.Find(QuickTalk).gameObject;
|
||||
@@ -103,36 +89,82 @@ namespace AibisDream
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 切换对话UI
|
||||
/// 注册对话框
|
||||
/// </summary>
|
||||
/// <param name="viewType">UI类型</param>
|
||||
/// <returns></returns>
|
||||
public IDialogView SwitchDialogView(DialogViewType viewType)
|
||||
/// <param name="viewType"></param>
|
||||
/// <param name="dialogView"></param>
|
||||
public void RegisterDialogView(DialogViewType viewType, IDialogView dialogView)
|
||||
{
|
||||
var newDlg = viewType switch
|
||||
{
|
||||
DialogViewType.Bubble => _bubbleView,
|
||||
DialogViewType.OldBox => _oldBoxView,
|
||||
_ => _oldBoxView
|
||||
};
|
||||
|
||||
if (_curView != newDlg)
|
||||
{
|
||||
_curView.HideDialog();
|
||||
_curView = newDlg;
|
||||
}
|
||||
|
||||
return _curView;
|
||||
_dialogViewDict.Add(viewType, dialogView);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取当前正在使用的Dialog View
|
||||
/// 注销对话框
|
||||
/// </summary>
|
||||
/// <returns>当前正在使用的Dialog View</returns>
|
||||
/// <exception cref="Exception">未找到Canvas</exception>
|
||||
public static IDialogView GetCurView()
|
||||
/// <param name="viewType"></param>
|
||||
public void UnregisterDialogView(DialogViewType viewType)
|
||||
{
|
||||
return Instance._curView;
|
||||
_dialogViewDict.Remove(viewType);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 对话框接口
|
||||
|
||||
public void ShowLine(string dialogLine, CharacterVo character, Action nextStep, Action onTextShowed = null,
|
||||
bool isAutoSkip = false)
|
||||
{
|
||||
// 根据DialogViewType确定在哪个对话框显示
|
||||
if (character.dialogViewType == DialogViewType.Default)
|
||||
{
|
||||
_lastShowView = _curView;
|
||||
// 没有指定对话框,就用当前激活的
|
||||
_curView.ShowLine(dialogLine, character, nextStep, onTextShowed, isAutoSkip);
|
||||
}
|
||||
else if (_dialogViewDict.TryGetValue(character.dialogViewType, out var view))
|
||||
{
|
||||
_lastShowView = view;
|
||||
// 对于指定了对话框的,就在指定对话框显示
|
||||
view.ShowLine(dialogLine, character, nextStep, onTextShowed, isAutoSkip);
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.Log($"{character.dialogViewType.ToString()}类型对话框不存在");
|
||||
}
|
||||
}
|
||||
|
||||
public void ShowOptions(DialogOption[] dialogueOptions)
|
||||
{
|
||||
// 暂时全部使用Box做选择,后面应该会有其他选择框
|
||||
_dialogViewDict[DialogViewType.OldBox].ShowOptions(dialogueOptions);
|
||||
}
|
||||
|
||||
public void HideDialog()
|
||||
{
|
||||
_curView.HideDialog();
|
||||
}
|
||||
|
||||
public bool TrySkipLine()
|
||||
{
|
||||
return _lastShowView.TrySkipLine();
|
||||
}
|
||||
|
||||
public void NextStep()
|
||||
{
|
||||
_lastShowView.NextStep();
|
||||
}
|
||||
|
||||
public void SwitchDialogView(DialogViewType dialogViewType)
|
||||
{
|
||||
if (_dialogViewDict.TryGetValue(dialogViewType, out var view))
|
||||
{
|
||||
_curView.HideDialog();
|
||||
_curView = view;
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.Log($"{dialogViewType.ToString()}类型对话框不存在");
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
@@ -145,7 +177,7 @@ namespace AibisDream
|
||||
/// 记录对话
|
||||
/// </summary>
|
||||
/// <param name="line">对话</param>
|
||||
private void AddDialogueLine(DialogLine line)
|
||||
private void AddDialogueLine(DialogText line)
|
||||
{
|
||||
logText.text += line.GetDialogText();
|
||||
}
|
||||
@@ -170,7 +202,9 @@ namespace AibisDream
|
||||
|
||||
public enum DialogViewType
|
||||
{
|
||||
Default,
|
||||
Bubble,
|
||||
OldBox
|
||||
OldBox,
|
||||
Screen
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user