QQ扫一扫联系
webGL好多字体不支持,写一个批量替换字体的小工具,替换成支持显示的
[MenuItem("GM/批量替换字体 %E")] public static void ChangeFonts() { string newFontPath = "Assets/Font/HuaKangJinGangHei.ttf"; Font font = AssetDatabase.LoadAssetAtPath<Font>(newFontPath); string[] guids = AssetDatabase.FindAssets("t:Prefab"); for (int i = 0; i < guids.Length; i++) { bool isChange = false; string prefabPath = AssetDatabase.GUIDToAssetPath(guids[i]); if (EditorUtility.DisplayCancelableProgressBar($"扫描中{i + 1}/{guids.Length}", prefabPath, (float)(i + 1) / guids.Length)) { EditorUtility.ClearProgressBar(); return; } GameObject gameObject = PrefabUtility.LoadPrefabContents(prefabPath); //获取隐藏的对象上的Text组件,需要在GetComponentsInChildren()函数中添加true参数以查找禁用的对象 Text[] texts = gameObject.transform.GetComponentsInChildren<Text>(true); foreach (var item in texts) { if (item.font != font) { item.font = font; isChange = true; } } if (isChange) { PrefabUtility.SaveAsPrefabAsset(gameObject, prefabPath); PrefabUtility.UnloadPrefabContents(gameObject); } } EditorUtility.ClearProgressBar(); UnityEngine.Debug.Log("Done"); }