using System; using AibisDream.Framework; using AibisDream.Kit; using AibisDream.Utility; using Febucci.UI; using TMPro; using UnityEngine; using UnityEngine.UI; namespace AibisDream { public class CenterText : MonoBehaviour, IDialogView { #region 索引 private TypewriterByCharacter _dialogText; private Image _panel; private Action _nextStep; #endregion private TextParam _textParam; private void Awake() { InitComponents(); } private void InitComponents() { _dialogText = transform.Find("Dialog Text")?.gameObject.GetComponent(); } public void ShowLine(string dialogLine, CharacterVo character, Action nextStep, string lineId, bool isAutoSkip = false) { // 把原有对话清掉 ClearBox(); _dialogText.gameObject.SetActive(true); // 显示内容 _dialogText.ShowText(dialogLine); // 自动跳过的回调很难独立Remove,只能全部清空再注册,下策 _dialogText.onTextShowed.RemoveAllListeners(); _dialogText.onTextShowed.AddListener(() => EnumEventSystem.Global.Send(DialogEventEnum.LineShown)); _nextStep = nextStep; } public void ShowOptions(DialogOption[] dialogueOptions) { // 不能出选项 } public void HideDialog() { gameObject.SetActive(false); } public bool TrySkipLine(bool isForceSkip) { if (_dialogText.isShowingText) { _dialogText.SkipTypewriter(); return true; } return false; } public void NextStep() { if (_nextStep == null) return; ClearBox(); var next = _nextStep; _nextStep = null; next.Invoke(); } public void OnLocalizationChanged(string value) { _textParam = JsonUtil.ReadBeanByText(value); var tmp = _dialogText.GetComponent(); // 修改对话文本 tmp.characterSpacing = _textParam.charSpace; } private void ClearBox() { gameObject.SetActive(true); _dialogText?.TextAnimator.SetText(""); } } }