ソースコード
using TMPro; using UnityEngine; namespace Kogane { public static class TextMeshProTagRemover { public static string Remove( string text ) { var gameObject = new GameObject(); var textMeshPro = gameObject.AddComponent<TextMeshPro>(); textMeshPro.text = text; textMeshPro.ForceMeshUpdate(); var parsedText = textMeshPro.GetParsedText(); Object.Destroy( gameObject ); return parsedText; } } }
使用例
using Kogane; using UnityEngine; public class Example : MonoBehaviour { private void Start() { // Red Debug.Log( TextMeshProTagRemover.Remove( @"<b><i><color=""red"">Red</color></i></b>" ) ); } }
注意
FontAsset に登録されている文字のみ対応しています