using System.Text; using Common.Utility.CombatEvent; using UnityEngine; namespace Fort23.Mono { [UIBinding(prefab = "DialoguePanel")] public partial class DialoguePanel : UIPanel { private string[] dialogueMessaga; private ShowDialogueEventData.MessageShowType messageShowType; private System.Action finish; private int index; private char[] _currShowMessage; private float _showTime = 0.05f; private float _currShowTime = 0; protected StringBuilder _sb = new StringBuilder(); private int _currShowIndex; private bool _isUpdate; private bool _isShowNextButton; private string[] showIconName; public static async void OpenDialoguePanel(string[] dialogueMessaga, string[] icon, ShowDialogueEventData.MessageShowType messageShowType, System.Action finish) { DialoguePanel dialoguePanel = await UIManager.Instance.LoadAndOpenPanel(null, UILayer.Top); // dialoguePanel.GObjectPoolInterface.SetActive(false); dialoguePanel.ShowPanel(dialogueMessaga, icon, messageShowType, finish); } private void Init() { } protected override void AddEvent() { } protected override void DelEvent() { } public override void AddButtonEvent() { nextButton.onClick.AddListener(NextShow); } private void NextShow() { StartShowMassge(); } public void ShowPanel(string[] dialogueMessaga, string[] icon, ShowDialogueEventData.MessageShowType messageShowType, System.Action finish) { showIconName = icon; this.dialogueMessaga = dialogueMessaga; this.messageShowType = messageShowType; this.finish = finish; index = 0; StaticUpdater.Instance.AddRenderUpdateCallBack(Update); StartShowMassge(); } private void StartShowMassge() { if (index >= dialogueMessaga.Length) { UIManager.Instance.HideUIUIPanel(this); finish?.Invoke(); return; } _isShowNextButton = false; nextIcon.SetActive(false); string m = dialogueMessaga[index]; if (showIconName != null && index < showIconName.Length) { icon.icon_name= showIconName[index]; } index++; switch (messageShowType) { case ShowDialogueEventData.MessageShowType.Default: message.text = m; ShowNextIcon(); break; case ShowDialogueEventData.MessageShowType.Verbatim: _sb.Clear(); _currShowMessage = m.ToCharArray(); _sb.Append(_currShowMessage[0]); message.text = _sb.ToString(); _isUpdate = true; _currShowIndex = 1; break; } } private void ShowNextIcon() { nextIcon.SetActive(true); _isShowNextButton = true; } public override void Hide() { base.Hide(); StaticUpdater.Instance.RemoveRenderUpdateCallBack(Update); } public void Update() { if (!_isUpdate) { return; } if (messageShowType == ShowDialogueEventData.MessageShowType.Verbatim) { if (_currShowIndex >= _currShowMessage.Length) { _isUpdate = false; ShowNextIcon(); return; } _currShowTime += Time.deltaTime; if (_currShowTime > _showTime) { _currShowTime -= _showTime; _sb.Append(_currShowMessage[_currShowIndex]); _currShowIndex++; message.text = _sb.ToString(); } } } } }