using System; using AibisDream.Framework; using AibisDream.Kit; using AibisDream.Utility; using Febucci.UI; using UnityEngine; using UnityEngine.UI; namespace AibisDream { public class CenterText : MonoBehaviour, IDialogView { #region 索引 private TypewriterByCharacter _dialogText; private Image _panel; private Action _nextStep; #endregion private bool _skipLineDelay; [Header("跳过阻塞延迟时间/ms")] [SerializeField] private int delayTime = 300; private void Awake() { InitComponents(); AddSomeListener(); } private void InitComponents() { _dialogText = transform.Find("Dialog Text")?.gameObject.GetComponent(); } private void AddSomeListener() { // 对话显示后有一段延时不可跳过 _dialogText.onTypewriterStart.AddListener(() => { _skipLineDelay = true; _ = CommonUtil.Delay(delayTime, () => { _skipLineDelay = false; }); }); } public void ShowLine(string dialogLine, CharacterVo character, Action nextStep, Action onTextShowed = null, bool isAutoSkip = false) { // 把原有对话清掉 ClearBox(); _dialogText.gameObject.SetActive(true); // 显示内容 _dialogText.ShowText(dialogLine); // 自动跳过的回调很难独立Remove,只能全部清空再注册,下策 _dialogText.onTextShowed.RemoveAllListeners(); _dialogText.onTextShowed.AddListener(() => onTextShowed?.Invoke()); _dialogText.onTextShowed.AddListener(() => EnumEventSystem.Global.Send(DialogEventEnum.LineShowed)); _nextStep = nextStep; // 执行自动跳过结局 if (isAutoSkip) { _dialogText.onTextShowed.AddListener(() => _ = CommonUtil.Delay(200, NextStep)); } } public void ShowOptions(DialogOption[] dialogueOptions) { // 不能出选项 } public void HideDialog() { gameObject.SetActive(false); } public bool TrySkipLine() { if (_skipLineDelay) { return true; } if (_dialogText.isShowingText) { _dialogText.SkipTypewriter(); return true; } return false; } public void NextStep() { if (_nextStep == null) return; ClearBox(); EnumEventSystem.Global.Send(DialogEventEnum.LineEnd); var next = _nextStep; _nextStep = null; next.Invoke(); } private void ClearBox() { gameObject.SetActive(true); _dialogText?.TextAnimator.SetText(""); } } }