本地化问题修改

This commit is contained in:
2025-05-09 18:54:30 +08:00
parent 107a6cbc4b
commit e7b30e25e5
17 changed files with 635 additions and 210 deletions
@@ -16,6 +16,7 @@ namespace AibisDream.FixSystem
public float rotateDuration = 0.5f;
public float typeSpeed = 0.05f;
public int maxTextLine;
#endregion
@@ -26,9 +27,12 @@ namespace AibisDream.FixSystem
[SerializeField] private TMP_Text text;
[SerializeField] private SpriteRenderer screenImage;
private Material _imageMaterial;
private Action _nextStep;
private TextGenerator _generator;
private TextGenerationSettings _generationSettings;
private IUnRegister _plugOutRmv;
private Action _nextStep;
#endregion
@@ -42,6 +46,18 @@ namespace AibisDream.FixSystem
{
_textScreen = transform.Find("旋转屏幕");
_imageMaterial = screenImage.material;
_generator = new TextGenerator();
_generationSettings = new TextGenerationSettings
{
font = text.font.sourceFontFile,
fontSize = Mathf.RoundToInt(text.fontSize),
lineSpacing = text.lineSpacing,
horizontalOverflow = HorizontalWrapMode.Wrap,
verticalOverflow = VerticalWrapMode.Truncate,
generationExtents = new Vector2(text.rectTransform.rect.width, Mathf.Infinity),
resizeTextForBestFit = false
};
}
private void Register()
@@ -76,18 +92,43 @@ namespace AibisDream.FixSystem
{
text.text += "\n";
}
// 先估算新增行数
var targetLineNum = EstimateLineNum(targetText);
// 截断超出屏幕的部分
var oldText = "";
if (targetLineNum + text.textInfo.lineCount > maxTextLine)
{
var cutLineNum = targetLineNum + text.textInfo.lineCount - maxTextLine;
if (cutLineNum <= text.textInfo.lineCount)
{
var lastCharIndex = text.textInfo.lineInfo[cutLineNum - 1].lastCharacterIndex;
oldText = text.text[lastCharIndex..];
}
}
else
{
oldText = text.text;
}
var oldText = text.text;
var targetLength = text.text.Length + targetText.Length;
var targetLength = oldText.Length + targetText.Length;
// 逐个字符添加
yield return DOTween.To(() => text.text.Length, x => UpdateText(x, targetText, oldText), targetLength,
yield return DOTween.To(() => oldText.Length, x => UpdateText(x, targetText, oldText), targetLength,
targetText.Length * typeSpeed).WaitForCompletion();
EnumEventSystem.Global.Send(DialogEventEnum.LineShown);
yield return new WaitForSeconds(0.5f);
EnumEventSystem.Global.Send(DialogEventEnum.LineEnd);
_nextStep.Invoke();
}
private int EstimateLineNum(string str)
{
var height = _generator.GetPreferredHeight(str, _generationSettings);
var lineHeight = text.fontSize * 1.2f; // 简单估算行高
return Mathf.CeilToInt(height / lineHeight);
}
private void UpdateText(int currentLength, string nextText, string oldText)
{