using AibisDream.Framework; using AibisDream.Kit; using AibisDream.Utility; using Febucci.UI.Core; using TMPro; using UnityEngine; namespace AibisDream { public class Bubble : MonoBehaviour { private TypewriterCore _typewriter; private TMP_Text _actorName; #region 参数 [SerializeField] public ActorRole role; [SerializeField] public int idx; [SerializeField] private int maxCharNum; #endregion public bool IsShowingText => _typewriter.isShowingText; private void Awake() { _typewriter = GetComponentInChildren(); _actorName = transform.Find("Actor")?.GetComponent(); _typewriter.onTextShowed.AddListener(() => EnumEventSystem.Global.Send(DialogEventEnum.LineShown)); } public void ShowActorName(CharacterVo characterVo) { if (!_actorName) return; _actorName.text = string.IsNullOrEmpty(characterVo.GetActorName()) ? string.Empty : characterVo.GetActorName(); } public void ShowLine(string line) { _typewriter.TextAnimator.SetText(""); gameObject.SetActive(true); var formattedLine = CommonUtil.SplitString(line, maxCharNum); _typewriter.ShowText(formattedLine); } public void SkipLine() { if (_typewriter.isShowingText) { _typewriter.SkipTypewriter(); } } public void Hide() { gameObject.SetActive(false); } public void OnLocalizationChanged(string value) { var textParam = JsonUtil.ReadBeanByText(value); var tmp = GetComponentInChildren(); tmp.characterSpacing = textParam.charSpace; _actorName.characterSpacing = textParam.charSpace; maxCharNum = textParam.maxCharNum; } } }