Ver.0.3.0.33
This commit is contained in:
@@ -1,23 +1,37 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using AibisDream.Framework;
|
||||
using AibisDream.Kit;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace AibisDream
|
||||
{
|
||||
public class DialogCanvasManager : Singleton<DialogCanvasManager>, IDialogView
|
||||
{
|
||||
private const string QuickTalk = "Quick Talk";
|
||||
|
||||
#region 引用
|
||||
|
||||
private readonly Dictionary<DialogViewType, IDialogView> _dialogViewDict = new();
|
||||
private IDialogView _curView;
|
||||
private IDialogView _lastShowView;
|
||||
private GameObject _quickTalkButton;
|
||||
private IDialogView _defaultView;
|
||||
private IDialogView _showingView;
|
||||
|
||||
private IActionController _autoNext;
|
||||
private IActionController _block;
|
||||
private IActionController _hideDialog;
|
||||
|
||||
public TMP_Text widthEstimation;
|
||||
|
||||
#endregion
|
||||
|
||||
#region 参数
|
||||
|
||||
[SerializeField] private float blockDuration;
|
||||
[SerializeField] private float autoSkipDelay;
|
||||
[SerializeField] private float autoHideDuration;
|
||||
|
||||
private bool _isNextAutoSkip;
|
||||
private bool _isNextBlocked;
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -25,25 +39,27 @@ namespace AibisDream
|
||||
|
||||
public override void OnSingletonInit()
|
||||
{
|
||||
InitQuickTalkButton();
|
||||
InitEvent();
|
||||
|
||||
// 默认对话框直接加载
|
||||
var box = transform.Find("Dialog Box").GetComponent<IDialogView>();
|
||||
RegisterDialogView(DialogViewType.OldBox, box);
|
||||
var centerText = transform.Find("Center Text").GetComponent<IDialogView>();
|
||||
RegisterDialogView(DialogViewType.CenterText, centerText);
|
||||
var centerOption = transform.Find("Center Option").GetComponent<IDialogView>();
|
||||
RegisterDialogView(DialogViewType.CenterOption, centerOption);
|
||||
}
|
||||
|
||||
private void Start()
|
||||
{
|
||||
_curView = _dialogViewDict[DialogViewType.OldBox];
|
||||
// 默认对话框直接加载
|
||||
// var box = transform.Find("Dialog Box").GetComponent<IDialogView>();
|
||||
// RegisterDialogView(DialogViewType.OldBox, box);
|
||||
var centerText = transform.Find("Center Text").GetComponent<IDialogView>();
|
||||
RegisterDialogView(DialogViewType.CenterText, centerText);
|
||||
var centerOption = transform.Find("Center Option").GetComponent<IDialogView>();
|
||||
RegisterDialogView(DialogViewType.CenterOption, centerOption);
|
||||
var bubbleGroup = transform.Find("Bubble Group").GetComponent<IDialogView>();
|
||||
RegisterDialogView(DialogViewType.StandardBubble, bubbleGroup);
|
||||
|
||||
_defaultView = _dialogViewDict[DialogViewType.StandardBubble];
|
||||
}
|
||||
|
||||
private void InitEvent()
|
||||
{
|
||||
// 记录相关
|
||||
_rmvList.Add(
|
||||
EnumEventSystem.Global.Register<DialogEventEnum, DialogText>(DialogEventEnum.LineStart,
|
||||
AddDialogueLine));
|
||||
@@ -51,6 +67,45 @@ namespace AibisDream
|
||||
EnumEventSystem.Global.Register<DialogEventEnum, DialogText>(DialogEventEnum.OptionSelected,
|
||||
AddDialogueLine));
|
||||
_rmvList.Add(EnumEventSystem.Global.Register(EventEnum.NextYarn, CleanDialogHistory));
|
||||
|
||||
// 文本显示事件
|
||||
_rmvList.Add(EnumEventSystem.Global.Register(DialogEventEnum.LineShown, OnTextShown));
|
||||
_rmvList.Add(EnumEventSystem.Global.Register(DialogEventEnum.LineEnd, OnTextEnd));
|
||||
}
|
||||
|
||||
private void OnTextShown()
|
||||
{
|
||||
// 阻塞部分
|
||||
_isNextBlocked = true;
|
||||
_block = ActionKit.Delay(blockDuration, () =>
|
||||
{
|
||||
_isNextBlocked = false;
|
||||
_block = null;
|
||||
}
|
||||
).Start(this);
|
||||
|
||||
// 自动跳过部分
|
||||
if (DialogController.Instance.quickRunMode) return;
|
||||
|
||||
if (DialogController.Instance.autoRunMode || _isNextAutoSkip)
|
||||
{
|
||||
_autoNext = ActionKit.Delay(autoSkipDelay, () =>
|
||||
{
|
||||
_autoNext = null;
|
||||
NextStep();
|
||||
}).Start(this);
|
||||
_isNextAutoSkip = false;
|
||||
}
|
||||
}
|
||||
|
||||
private void OnTextEnd()
|
||||
{
|
||||
_block?.Deinit();
|
||||
_block = null;
|
||||
_isNextBlocked = false;
|
||||
|
||||
_autoNext?.Deinit();
|
||||
_autoNext = null;
|
||||
}
|
||||
|
||||
public override void OnSingletonDestroy()
|
||||
@@ -73,29 +128,8 @@ namespace AibisDream
|
||||
|
||||
#endregion
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (Input.GetKeyDown(KeyCode.Q) && Input.GetKey(KeyCode.P))
|
||||
{
|
||||
_quickTalkButton.SetActive(!_quickTalkButton.activeSelf);
|
||||
}
|
||||
}
|
||||
|
||||
#region 对话框相关处理
|
||||
|
||||
private void InitQuickTalkButton()
|
||||
{
|
||||
_quickTalkButton = transform.Find(QuickTalk).gameObject;
|
||||
_quickTalkButton.GetComponent<Button>().onClick.AddListener(SwitchQuickTalkMode);
|
||||
}
|
||||
|
||||
private void SwitchQuickTalkMode()
|
||||
{
|
||||
DialogController.Instance.quickRunMode = !DialogController.Instance.quickRunMode;
|
||||
_quickTalkButton.GetComponent<Image>().color =
|
||||
DialogController.Instance.quickRunMode ? Color.gray : Color.white;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 注册对话框
|
||||
/// </summary>
|
||||
@@ -119,30 +153,43 @@ namespace AibisDream
|
||||
|
||||
#region 对话框接口
|
||||
|
||||
public void ShowLine(string dialogLine, CharacterVo character, Action nextStep, bool isAutoSkip = false)
|
||||
public void ShowLine(string dialogLine, CharacterVo character, Action nextStep, string lineId,
|
||||
bool isAutoSkip = false)
|
||||
{
|
||||
_isNextAutoSkip = isAutoSkip;
|
||||
// 根据DialogViewType确定在哪个对话框显示
|
||||
if (character.dialogViewType == DialogViewType.Default)
|
||||
{
|
||||
if (_lastShowView != _curView)
|
||||
if (_showingView != _defaultView)
|
||||
{
|
||||
_lastShowView?.HideDialog();
|
||||
_showingView?.HideDialog();
|
||||
}
|
||||
else
|
||||
{
|
||||
_hideDialog?.Deinit();
|
||||
_hideDialog = null;
|
||||
}
|
||||
|
||||
_lastShowView = _curView;
|
||||
// 没有指定对话框,就用当前激活的
|
||||
_curView.ShowLine(dialogLine, character, nextStep, isAutoSkip);
|
||||
_showingView = _defaultView;
|
||||
|
||||
_showingView.ShowLine(dialogLine, character, nextStep, lineId, isAutoSkip);
|
||||
}
|
||||
else if (_dialogViewDict.TryGetValue(character.dialogViewType, out var view))
|
||||
{
|
||||
if (_lastShowView != view)
|
||||
if (_showingView != view)
|
||||
{
|
||||
_lastShowView?.HideDialog();
|
||||
_showingView?.HideDialog();
|
||||
}
|
||||
else
|
||||
{
|
||||
_hideDialog?.Deinit();
|
||||
_hideDialog = null;
|
||||
}
|
||||
|
||||
_lastShowView = view;
|
||||
_showingView = view;
|
||||
|
||||
// 对于指定了对话框的,就在指定对话框显示
|
||||
view.ShowLine(dialogLine, character, nextStep, isAutoSkip);
|
||||
view.ShowLine(dialogLine, character, nextStep, lineId, isAutoSkip);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -156,37 +203,72 @@ namespace AibisDream
|
||||
// 根据状况选择不同的选择框
|
||||
if (viewType == DialogViewType.Default)
|
||||
{
|
||||
_dialogViewDict[DialogViewType.OldBox].ShowOptions(dialogueOptions);
|
||||
if (_showingView != _defaultView)
|
||||
{
|
||||
_showingView?.HideDialog();
|
||||
}
|
||||
else
|
||||
{
|
||||
_hideDialog?.Deinit();
|
||||
_hideDialog = null;
|
||||
}
|
||||
_showingView = _defaultView;
|
||||
|
||||
_showingView.ShowOptions(dialogueOptions);
|
||||
}
|
||||
else
|
||||
else if(_dialogViewDict.TryGetValue(viewType, out var view))
|
||||
{
|
||||
_dialogViewDict[viewType].ShowOptions(dialogueOptions);
|
||||
if (_showingView != view)
|
||||
{
|
||||
_showingView?.HideDialog();
|
||||
}
|
||||
else
|
||||
{
|
||||
_hideDialog?.Deinit();
|
||||
_hideDialog = null;
|
||||
}
|
||||
_showingView = view;
|
||||
_showingView.ShowOptions(dialogueOptions);
|
||||
}
|
||||
}
|
||||
|
||||
public void HideDialog()
|
||||
{
|
||||
_curView.HideDialog();
|
||||
_showingView?.HideDialog();
|
||||
}
|
||||
|
||||
public bool TrySkipLine(bool isForceSkip = false)
|
||||
{
|
||||
return _lastShowView != null && _lastShowView.TrySkipLine(isForceSkip);
|
||||
if (_isNextBlocked)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return _showingView != null && _showingView.TrySkipLine(isForceSkip);
|
||||
}
|
||||
|
||||
public void NextStep()
|
||||
{
|
||||
_lastShowView?.NextStep();
|
||||
var view = _showingView;
|
||||
_hideDialog = ActionKit.Delay(autoHideDuration, () =>
|
||||
{
|
||||
_hideDialog = null;
|
||||
view.HideDialog();
|
||||
}).Start(this);
|
||||
_showingView?.NextStep();
|
||||
}
|
||||
|
||||
public void OnLocalizationChanged(string value)
|
||||
{
|
||||
}
|
||||
|
||||
public void SwitchDialogView(DialogViewType dialogViewType)
|
||||
{
|
||||
if (_dialogViewDict.TryGetValue(dialogViewType, out var view))
|
||||
{
|
||||
_curView.HideDialog();
|
||||
_lastShowView?.HideDialog();
|
||||
_lastShowView = null;
|
||||
_curView = view;
|
||||
_defaultView?.HideDialog();
|
||||
_showingView?.HideDialog();
|
||||
_defaultView = view;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -198,7 +280,7 @@ namespace AibisDream
|
||||
|
||||
#region 对话回顾
|
||||
|
||||
[Header("对话回顾组件")] [SerializeField] private TMP_Text logText;
|
||||
private StringBuilder DialogRecord => UIManager.Instance.GetPanel<RecordPanel>().recordStr;
|
||||
|
||||
/// <summary>
|
||||
/// 记录对话
|
||||
@@ -206,25 +288,33 @@ namespace AibisDream
|
||||
/// <param name="line">对话</param>
|
||||
private void AddDialogueLine(DialogText line)
|
||||
{
|
||||
logText.text += line.GetDialogText();
|
||||
DialogRecord.Append(line.GetDialogText());
|
||||
}
|
||||
|
||||
private void CleanDialogHistory()
|
||||
{
|
||||
logText.text = null;
|
||||
DialogRecord.Clear();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 切换对话回顾展示状态
|
||||
/// </summary>
|
||||
public void ControlDialogHistory()
|
||||
public void CloseCanvas()
|
||||
{
|
||||
var logObj = transform.Find("Dialogue Log").gameObject;
|
||||
logObj.SetActive(!logObj.activeSelf);
|
||||
EnumEventSystem.Global.Send(EventEnum.Menu, logObj.activeSelf);
|
||||
gameObject.SetActive(false);
|
||||
}
|
||||
|
||||
public void OpenCanvas()
|
||||
{
|
||||
gameObject.SetActive(true);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
public float EstimateTextWidth(string text, float fontSize)
|
||||
{
|
||||
widthEstimation.fontSize = fontSize;
|
||||
widthEstimation.text = text;
|
||||
widthEstimation.ForceMeshUpdate();
|
||||
return widthEstimation.preferredWidth;
|
||||
}
|
||||
}
|
||||
|
||||
public enum DialogViewType
|
||||
@@ -234,6 +324,8 @@ namespace AibisDream
|
||||
OldBox,
|
||||
Screen,
|
||||
CenterText,
|
||||
CenterOption
|
||||
CenterOption,
|
||||
Task,
|
||||
StandardBubble
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user