facebook twitter hatena line email

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

提供: 初心者エンジニアの簡易メモ
移動: 案内検索
(使い方)
行11: 行11:
  
 
参考:https://kan-kikuchi.hatenablog.com/entry/TextMeshPro_Migration
 
参考:https://kan-kikuchi.hatenablog.com/entry/TextMeshPro_Migration
 +
 +
==全Textを対応する==
 +
ReplaceCurrentSceneメソッドを、以下の通り書き換える
 +
<pre>
 +
        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);
 +
                    }
 +
                }
 +
            }
 +
        }
 +
</pre>

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

使い方

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

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

全Textを対応する

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

        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);
                    }
                }
            }
        }