Commit 1fc80914 authored by Geri's avatar Geri
Browse files

fix: Now all characters are displaying properly

parent a3415767
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -891,7 +891,7 @@ MonoBehaviour:
  m_Script: {fileID: 11500000, guid: 6ce276be77304236a23df45b19b4cc08, type: 3}
  m_Name: 
  m_EditorClassIdentifier: 
  maxVisibleMessages: 3
  maxVisibleMessages: 5
  messageHeight: 16
  messagePrefab: {fileID: -6056302822753658535, guid: 6bf006df27e33a24088a28c9d46dbb43, type: 3}
--- !u!1 &1284257431
+6 −11
Original line number Diff line number Diff line
@@ -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;
		}
	}
}
 No newline at end of file