Files
aibis-dream/Assets/Scripts/UI/DialogUI/Bubbles/Bubble.cs
T
2025-06-04 21:45:50 +08:00

72 lines
2.0 KiB
C#

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<TypewriterCore>();
_actorName = transform.Find("Actor")?.GetComponent<TMP_Text>();
_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<TextParam>(value);
var tmp = GetComponentInChildren<TMP_Text>();
tmp.characterSpacing = textParam.charSpace;
_actorName.characterSpacing = textParam.charSpace;
maxCharNum = textParam.maxCharNum;
}
}
}