fix: Now all characters are displaying properly
This commit is contained in:
parent
a3415767cd
commit
1fc809141c
2 changed files with 7 additions and 12 deletions
|
@ -891,7 +891,7 @@ MonoBehaviour:
|
||||||
m_Script: {fileID: 11500000, guid: 6ce276be77304236a23df45b19b4cc08, type: 3}
|
m_Script: {fileID: 11500000, guid: 6ce276be77304236a23df45b19b4cc08, type: 3}
|
||||||
m_Name:
|
m_Name:
|
||||||
m_EditorClassIdentifier:
|
m_EditorClassIdentifier:
|
||||||
maxVisibleMessages: 3
|
maxVisibleMessages: 5
|
||||||
messageHeight: 16
|
messageHeight: 16
|
||||||
messagePrefab: {fileID: -6056302822753658535, guid: 6bf006df27e33a24088a28c9d46dbb43, type: 3}
|
messagePrefab: {fileID: -6056302822753658535, guid: 6bf006df27e33a24088a28c9d46dbb43, type: 3}
|
||||||
--- !u!1 &1284257431
|
--- !u!1 &1284257431
|
||||||
|
|
|
@ -16,21 +16,16 @@ namespace Messaging.Typer {
|
||||||
public IEnumerator AnimateTextIn(string processedMessage, Action onFinish) {
|
public IEnumerator AnimateTextIn(string processedMessage, Action onFinish) {
|
||||||
float timeOfLastCharacter = 0;
|
float timeOfLastCharacter = 0;
|
||||||
|
|
||||||
TMP_TextInfo textInfo = _textBox.textInfo;
|
|
||||||
|
|
||||||
_textBox.maxVisibleCharacters = 0;
|
_textBox.maxVisibleCharacters = 0;
|
||||||
_textBox.text = processedMessage;
|
_textBox.text = processedMessage;
|
||||||
_textBox.ForceMeshUpdate();
|
_textBox.ForceMeshUpdate();
|
||||||
|
|
||||||
int charCount = textInfo.characterCount;
|
|
||||||
int visibleCharacterIndex = 0;
|
|
||||||
while (true) {
|
while (true) {
|
||||||
if (ShouldShowNextCharacter(SecondsPerCharacter, timeOfLastCharacter)) {
|
if (ShouldShowNextCharacter(timeOfLastCharacter)) {
|
||||||
if (visibleCharacterIndex <= charCount) {
|
if (_textBox.maxVisibleCharacters <= _textBox.textInfo.characterCount) {
|
||||||
visibleCharacterIndex++;
|
_textBox.maxVisibleCharacters++;
|
||||||
_textBox.maxVisibleCharacters = visibleCharacterIndex;
|
|
||||||
timeOfLastCharacter = Time.unscaledTime;
|
timeOfLastCharacter = Time.unscaledTime;
|
||||||
if (visibleCharacterIndex == charCount) {
|
if (_textBox.maxVisibleCharacters == _textBox.textInfo.characterCount) {
|
||||||
onFinish?.Invoke();
|
onFinish?.Invoke();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -41,8 +36,8 @@ namespace Messaging.Typer {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static bool ShouldShowNextCharacter(float secondsPerCharacter, float timeOfLastCharacter) {
|
private static bool ShouldShowNextCharacter(float timeOfLastCharacter) {
|
||||||
return Time.unscaledTime - timeOfLastCharacter > secondsPerCharacter;
|
return Time.unscaledTime - timeOfLastCharacter > SecondsPerCharacter;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Add table
Add a link
Reference in a new issue