123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137 |
- 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;
- public static async void OpenDialoguePanel(string[] dialogueMessaga,
- ShowDialogueEventData.MessageShowType messageShowType,
- System.Action finish)
- {
- DialoguePanel dialoguePanel = await UIManager.Instance.LoadAndOpenPanel<DialoguePanel>(null, UILayer.Top);
- // dialoguePanel.GObjectPoolInterface.SetActive(false);
- dialoguePanel.ShowPanel(dialogueMessaga, 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, ShowDialogueEventData.MessageShowType messageShowType,
- System.Action finish)
- {
- 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];
- 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();
- }
- }
- }
- }
- }
|