facebook twitter hatena line email

「Unity/TMPro/TextからTMProへ」の版間の差分

提供: 初心者エンジニアの簡易メモ
移動: 案内検索
(全Textを対応する)
行6: 行6:
  
 
<pre>
 
<pre>
201 - if (fontAsset.fontInfo.Name.Equals(m_font.name, System.StringComparison.OrdinalIgnoreCase))
+
176 - if (fontAsset.fontInfo.Name.Equals(m_font.name, System.StringComparison.OrdinalIgnoreCase))
201 + if (fontAsset.name.Equals("NotoSansJP-Regular SDF", System.StringComparison.OrdinalIgnoreCase))
+
176 + if (fontAsset.name.Equals("NotoSansJP-Regular SDF", System.StringComparison.OrdinalIgnoreCase))
 
</pre>
 
</pre>
  

2023年1月6日 (金) 20:39時点における版

使い方

  1. ツールをDL https://github.com/jackisgames/TextMeshProReplacer
  2. CanvasUIEditor.csが、エラーになるので、このファイルのすべてを、コメントアウト対応
  3. TextReplacer.csの以下201行目辺りの行を修正し、フォント名を入れる
  4. unityメニューのwindow/ReplaceCurrentSceneをクリックで、TextをTextMeshProUGUIに置換される
176 - if (fontAsset.fontInfo.Name.Equals(m_font.name, System.StringComparison.OrdinalIgnoreCase))
176 + if (fontAsset.name.Equals("NotoSansJP-Regular SDF", System.StringComparison.OrdinalIgnoreCase))

参考:https://kan-kikuchi.hatenablog.com/entry/TextMeshPro_Migration

全Textを対応する

TextMeshProReplacerのTextReplacer.ReplaceCurrentSceneメソッドを、以下の通り書き換える


namespace TextMeshProReplacer
{
    internal class TextReplacer
    {
        [MenuItem("Text Mesh Replacer/Replace Current Scene")]
        internal static void ReplaceCurrentScene()
        {
            GameObject[] rootGameObjects = SceneManager.GetActiveScene().GetRootGameObjects();
            for (int i = 0; i < rootGameObjects.Length; i++)
            {
                GameObject root = rootGameObjects[i];
                AllUnderObject(root);
            }  
        }
        public static void AllUnderObject(GameObject obj)
        {
            Transform transforms = obj.GetComponentInChildren<Transform>();
            if (transforms.childCount > 0)
            {
                foreach (Transform transform in transforms)
                {
                    AllUnderObject(transform.gameObject);
                    Text text = transform.GetComponent<Text>();
                    if (text)
                    {
                        Debug.Log("name=" + transform.gameObject.name);
                        ReplaceUnityText(text);
                    }
                }
            }
        }