/// <summary> /// Pops in characters from the message over time /// </summary> private void ShowCharacter(BubbleMsg msg) { while (msg.elapsedTime > 0f) { if (msg.characterIndex > msg.msg.Length - 1) { break; } msg.elapsedTime -= msg.characterPopInSpeed; var currentCharacter = msg.msg[msg.characterIndex]; if (char.IsWhiteSpace(currentCharacter)) { msg.elapsedTime -= msg.characterPopInSpeed * 2f; } else if (char.IsPunctuation(currentCharacter)) { msg.elapsedTime -= msg.characterPopInSpeed * 3f; } var text = msg.msg.Substring(0, msg.characterIndex + 1); var newText = new StringBuilder(); //God Save Our Eyes if ((msg.modifier & ChatModifier.Clown) == ChatModifier.Clown && PlayerPrefs.GetInt(PlayerPrefKeys.ChatBubbleClownColour) == 1) { for (int i = 0; i < text.Length; i++) { newText.Append($"<color=#{RandomUtils.CreateRandomBrightColorString()}>{text[i]}</color>"); } } else { newText.Append(text); } if (msg.buffered && msg.characterIndex < msg.msg.Length - 1) { //Add the rest of the character but invisible to make bubble correct size //and keep the characters in the same place (helps reading) newText.Append($"<color=#00000000>{msg.msg.Substring(msg.characterIndex + 1)}</color>"); } SetBubbleParameters(newText.ToString(), msg.modifier); msg.characterIndex++; } }