Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
3.3k views
in Technique[技术] by (71.8m points)

css - How to translate TextMeshPro-StyleTags to the actual RichText in Unity?

I have the following string in TextMeshPro: "<style=Title>This is a Title (...)".

I would like to translate the StyleTag to the defined Opening Tags. For this example it would translate the string above to the following: "<size=125%><align=center>This is a Title (...)".

How can I do this?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You can get the OpeningTags to a StyleTag by calling the following function: TMP_StyleSheet.GetStyle("[StyleName]").styleOpeningDefinition (with TMP_StyleSheet being a reference to the used TMP-StyleSheet).

So a possible solution is to extract the StyleName from your string (e.g. "(...text) <style=Example> (text...)" would become "Example") and feed it to the function above. Regular Expressions can help to extract the StyleName from your string. Then replace the whole tag with whatever the function returns (e.g. "<size=125%>"). (Note: It returns Null if the tag does not exist). Then do the same with the closing tag.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...