Unity 一键替换字体工具

作者: 2b75747cf703 | 来源:发表于2016-07-12 13:38 被阅读926次

    打开预制体或者场景文件,可以看到。


    Paste_Image.png

    用正则表达式来匹配替换即可。

        [MenuItem("BabybusFrame/Utility/一键替换所有字体")]
        private static void ReplaceText()
        {
            var fileID = "12800000";
            var guid = "02dd88727fcbd8b46abd6f8636fec717";
            var type = 3;
    
            var pattern = "m_Font: {fileID: [0-9]+, guid: [0-9a-z]{32}, type: [0-9]+}";
            var replacement = "m_Font: {fileID: " + fileID + ", guid: " + guid + ", type: " + type +"}";
    
            var assets = AssetDatabase.FindAssets("t:Prefab t:SceneAsset");
    
            for (var i = 0; i < assets.Length; i++)
            {
                var assetPath = AssetDatabase.GUIDToAssetPath(assets[i]);
    
                EditorUtility.DisplayProgressBar("Hold on", assetPath, 1.0f * i / assets.Length);
    
                var input = File.ReadAllText(assetPath);
    
                var contents = Regex.Replace(input, pattern, replacement);
    
                File.WriteAllText(assetPath, contents);
            }
    
            EditorUtility.ClearProgressBar();
    
            AssetDatabase.Refresh();
        }
    

    相关文章

      网友评论

        本文标题:Unity 一键替换字体工具

        本文链接:https://www.haomeiwen.com/subject/pqtsjttx.html