62 lines
1.6 KiB
C#
62 lines
1.6 KiB
C#
using System;
|
|
using AibisDream.Kit;
|
|
using AibisDream.Utility;
|
|
using Febucci.UI.Core;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
|
|
namespace AibisDream.Framework
|
|
{
|
|
public class TextBubble : MonoBehaviour
|
|
{
|
|
private TypewriterCore _typewriter;
|
|
|
|
#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>();
|
|
}
|
|
|
|
public void ShowLine(string line, Action onTextEnd)
|
|
{
|
|
_typewriter.TextAnimator.SetText("");
|
|
gameObject.SetActive(true);
|
|
var formattedLine = CommonUtil.SplitString(line, maxCharNum);
|
|
_typewriter.ShowText(formattedLine);
|
|
// 对话结束回调
|
|
_typewriter.onTextShowed.RemoveAllListeners();
|
|
_typewriter.onTextShowed.AddListener(() => onTextEnd?.Invoke());
|
|
}
|
|
|
|
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;
|
|
maxCharNum = textParam.maxCharNum;
|
|
}
|
|
}
|
|
} |