When Super Text Mesh is in the editable mode, Is it possible to insert text/rich text pro grammatically into the current position of the caret? Is there an API to get the current position of the caret ? Thanks!
Text for Unity, Super-Powered! · By
Super Text Mesh is just meant to be a text renderer, so the type of code that would make this work for Unity's standard mesh will also work for STM.
If the caret is currently at index 3, then...
superTextMesh.text = superTextMesh.text.Insert("***", caretPosition);
should insert a string at the caret's position.
-Kai
Super Text Mesh is just a text renderer, not a text editor, so it doesn't have a caret it keeps track of by itself. To edit text at a certain position, you have to keep track of the "caret" with a variable.
Here's some pseudocode of how you can do this:
public int caretPosition = 0; public SuperTextMesh stm; public void InsertTextAtCaret(string newText){ //add the string to super text mesh's text variable at the caret's position stm.text = superTextMesh.text.Insert(newText, caretPosition);
}
To reiterate, this type of code can run in any string, not just Super Text Mesh's "text" variable!