private IEnumerator WriteText(float startDelay) { working = true; // Change our working state to true; yield return(new WaitForSecondsRealtime(startDelay)); timePerCharacter = TotalWriteTime / originalText.Length; OnTextWriterStart?.Invoke(); // Call our start delegate var size = originalText.Length; while (currIndex < size) { currIndex = SkipTokens(originalText, currIndex); // Skip tokens like <color></color> var newText = originalText.Substring(0, currIndex + 1); // Get the text we need to display var rest = originalText.Substring(currIndex + 1); if (InvisibleCharacterPadding) { var tokenlessText = RemoveAllTokens(rest); // Removes (temporarily) any future color tokens newText += "<color=#00000000>" + tokenlessText + "</color>"; // Hide the rest of the characters with an invisible character } TextMeshProTarget.text = newText; // Set it currIndex++; //Increment yield return(new WaitForSecondsRealtime(timePerCharacter)); // Wait for our desired time } OnTextWriterStop?.Invoke(); // Call our stop delegate working = false; // set our working state to false yield break; }
public void Restart() { OnTextWriterRestart?.Invoke(); // Call our delegate event Skip(); // Skip anything we're still writing TextMeshProTarget.text = ""; // Clear the text content of the object currIndex = 0; // Reset the index if (AutoStartWriting) { StartWriting(); } }