Files
aibis-dream/Assets/Scripts/UI/DialogUI/DialogUIManager.cs
T
dingyuntian 91ffbeb130 feat(ui): 添加录制工具面板
新增 RecordingToolPanel,按 Ctrl+R 唤出侧边栏,可独立控制光标、
版本号、Top Bar 与对话视觉的显隐。移除旧的
UIEventEnum.RecordingModeChanged 事件,改为各子系统提供显式
SetVisible API。在 Persistence 场景中配置面板层级与四个开关。
2026-07-15 16:51:55 +08:00

122 lines
3.6 KiB
C#

using AibisDream.Framework;
using AibisDream.Kit;
using AibisDream.UI;
using TMPro;
using UnityEngine;
namespace AibisDream
{
public class DialogUIManager : Singleton<DialogUIManager>
{
[SerializeField] private LineRunner lineView;
[SerializeField] private OptionView optionView;
[SerializeField] private TMP_Text widthEstimation;
private CanvasGroup _canvasGroup;
public override void OnSingletonInit()
{
_canvasGroup = GetComponent<CanvasGroup>();
if (_canvasGroup == null)
{
_canvasGroup = gameObject.AddComponent<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 void AddDialogueLine(LineInfo line)
{
if (line.character.dialogViewType == DialogViewType.Task)
{
return;
}
var panel = UIManager.Instance.GetPanel<InGameTerminalPanel>();
panel?.AppendDialogLine(line);
}
private void CleanDialogHistory()
{
var panel = UIManager.Instance.GetPanel<InGameTerminalPanel>();
panel?.ClearDialog();
}
public void CloseCanvas()
{
gameObject.SetActive(false);
}
public void OpenCanvas()
{
gameObject.SetActive(true);
}
/// <summary>
/// 仅隐藏对话视觉,不影响打字机、推进与选项交互。
/// </summary>
public void SetDialogVisualVisible(bool visible)
{
if (_canvasGroup == null)
{
_canvasGroup = GetComponent<CanvasGroup>();
}
_canvasGroup.alpha = visible ? 1f : 0f;
}
public void HideDialog()
{
lineView.HideDialog();
optionView.HideDialog();
}
public void RegisterScreenView(DialogViewType dialogViewType, ILineView screenView)
{
lineView.RegisterView(dialogViewType, screenView);
}
public void UnRegisterScreenView(DialogViewType dialogViewType)
{
lineView.UnRegisterView(dialogViewType);
}
public void LoadBubbles(BubbleSlotGroupData data)
{
lineView.LoadBubbleData(data);
optionView.LoadBubbles(data);
}
public float EstimateTextWidth(string text, float fontSize)
{
widthEstimation.fontSize = fontSize;
widthEstimation.text = text;
widthEstimation.ForceMeshUpdate();
return widthEstimation.preferredWidth;
}
}
public enum DialogViewType
{
Default,
StandardBubble,
OnelineBox,
Screen,
CenterText,
CenterOption,
Task,
Log
}
}