fix: Now all characters are displaying properly

This commit is contained in:
Gerard Gascón 2024-01-27 14:55:14 +01:00
parent a3415767cd
commit 1fc809141c
2 changed files with 7 additions and 12 deletions

View file

@ -16,21 +16,16 @@ namespace Messaging.Typer {
public IEnumerator AnimateTextIn(string processedMessage, Action onFinish) {
float timeOfLastCharacter = 0;
TMP_TextInfo textInfo = _textBox.textInfo;
_textBox.maxVisibleCharacters = 0;
_textBox.text = processedMessage;
_textBox.ForceMeshUpdate();
int charCount = textInfo.characterCount;
int visibleCharacterIndex = 0;
while (true) {
if (ShouldShowNextCharacter(SecondsPerCharacter, timeOfLastCharacter)) {
if (visibleCharacterIndex <= charCount) {
visibleCharacterIndex++;
_textBox.maxVisibleCharacters = visibleCharacterIndex;
if (ShouldShowNextCharacter(timeOfLastCharacter)) {
if (_textBox.maxVisibleCharacters <= _textBox.textInfo.characterCount) {
_textBox.maxVisibleCharacters++;
timeOfLastCharacter = Time.unscaledTime;
if (visibleCharacterIndex == charCount) {
if (_textBox.maxVisibleCharacters == _textBox.textInfo.characterCount) {
onFinish?.Invoke();
break;
}
@ -41,8 +36,8 @@ namespace Messaging.Typer {
}
}
private static bool ShouldShowNextCharacter(float secondsPerCharacter, float timeOfLastCharacter) {
return Time.unscaledTime - timeOfLastCharacter > secondsPerCharacter;
private static bool ShouldShowNextCharacter(float timeOfLastCharacter) {
return Time.unscaledTime - timeOfLastCharacter > SecondsPerCharacter;
}
}
}