using AibisDream.Framework; using AibisDream.Kit; using AibisDream.UI; using TMPro; using UnityEngine; namespace AibisDream { public class DialogUIManager : Singleton { [SerializeField] private LineRunner lineView; [SerializeField] private OptionView optionView; [SerializeField] private TMP_Text widthEstimation; public override void OnSingletonInit() { EnumEventSystem.Global.Register(DialogEventEnum.LineStart, AddDialogueLine); EnumEventSystem.Global.Register(DialogEventEnum.OptionSelected, AddDialogueLine); EnumEventSystem.Global.Register(EventEnum.NextYarn, CleanDialogHistory); EnumEventSystem.Global.Register(GameLoopEnum.GameQuit, CleanDialogHistory); } public override void OnSingletonDestroy() { EnumEventSystem.Global.UnRegister(DialogEventEnum.LineStart, AddDialogueLine); EnumEventSystem.Global.UnRegister(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(); panel?.AppendDialogLine(line); } private void CleanDialogHistory() { var panel = UIManager.Instance.GetPanel(); panel?.ClearDialog(); } public void CloseCanvas() { gameObject.SetActive(false); } public void OpenCanvas() { gameObject.SetActive(true); } 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 } }