Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modify TypedTextGenerator to use TextGenerator lines #12

Open
FeeeshMeister opened this issue Jun 28, 2017 · 2 comments
Open

Modify TypedTextGenerator to use TextGenerator lines #12

FeeeshMeister opened this issue Jun 28, 2017 · 2 comments

Comments

@FeeeshMeister
Copy link

FeeeshMeister commented Jun 28, 2017

The text generator currently moves an alpha tag to change what characters are visible, which is not optimal for garbage collection. A solution to this is to use the following code in place of the function that changes the location of the alpha tag, but some changes would likely need to be made since this is mostly unmodified from the system that I use.
// textField is the text object that the player sees, and is also where the unformatted text starts // I don't remember what tempString does, I just know that you need it // I also don't remember what start or end index do , but again, they are very important public void InitializeText() { textField.color = Color.clear; textField.text = text; Canvas.ForceUpdateCanvases(); for (int i = 0; i < textField.cachedTextGenerator.lines.Count; i++) { int startIndex = textField.cachedTextGenerator.lines[i].startCharIdx; int endIndex = (i == textField.cachedTextGenerator.lines.Count - 1) ? textField.text.Length : textField.cachedTextGenerator.lines[i + 1].startCharIdx; int length = endIndex - startIndex; tempString += textField.text.Substring(startIndex, length) + "\n"; } textField.text = string.Empty; textField.color = Color.white; // Replace with whatever color you need text = tempString; }
I'm sorry I don't know as much as I should about a script that I wrote, but I wrote this a very long time ago, and I never used to put comments in my code (I have since learned my lesson), so I hope you can make at least some sense of this. Despite all of these problems with it, I hope you get at least some use out of this script even though it was very poorly done, and i will probably need to redo it at some point

@FeeeshMeister
Copy link
Author

It looks like Github completely messed up the code, so here it is

public void InitializeText()
{
textField.color = Color.clear;
textField.text = text;
Canvas.ForceUpdateCanvases();
for (int i = 0; i < textField.cachedTextGenerator.lines.Count; i++)
{
int startIndex = textField.cachedTextGenerator.lines[i].startCharIdx;
int endIndex = (i == textField.cachedTextGenerator.lines.Count - 1) ? textField.text.Length : textField.cachedTextGenerator.lines[i + 1].startCharIdx;
int length = endIndex - startIndex;
tempString += textField.text.Substring(startIndex, length) + "\n";
}
textField.text = string.Empty;
textField.color = Color.white; // Replace with whatever color you need
text = tempString;
}

@edwardrowe
Copy link

Thanks for submitting the code sample! Some day soon I'll look to adapt the typer for Unity 2017 and Text Mesh Pro, and maybe this will come in handy.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants