public void rebuildFontAtlas(TMPFont font) { var bakeData = font.bakeData; var fullCharsPath = Path.Combine(Application.dataPath, charsPath); var charString = File.ReadAllText(Path.Combine(fullCharsPath, bakeData.characterTextFile + ".txt")); TMPFontAssetBaker.Bake(bakeData.baseFont, false, bakeData.fontSize, bakeData.padding, fontAtlasPackingMode, bakeData.atlasWidth, bakeData.atlasHeight, TMPro.EditorUtilities.FaceStyles.Normal, 2, TMPro.EditorUtilities.RenderModes.DistanceField16, charString, Path.Combine(fontsPath, font.fontAsset.name + ".asset"), bakeData.glyphOverrides); Debug.Log("Rebuilt atlas for " + font.idName); var missingCharData = GetMissingFontCharData(forceFont: font); foreach (var data in missingCharData) { Debug.LogWarning($"{data.font.fontAsset.name} is still missing {data.language.getFileName()} character(s) " + $"{data.missingChars}. Try expanding the atlas size, or maybe the characters are missing from the base font."); } if (!string.IsNullOrEmpty(bakeData.notes)) { Debug.Log("Notes about " + font.idName + ":\n" + bakeData.notes); } }
public static void DownloadAndBakeAllUsedLocalizationCharactersIntoFonts() { var charSet = new HashSet <char>(); LocalizationTable[] allTables = UnityEngine.Object.FindObjectsOfType <LocalizationConfiguration>().SelectMany(config => config.TableSources).Select(s => s.LoadTable()).ToArray(); foreach (var table in allTables) { foreach (var culture in table.AllCultures) { var textMap = table.GetTextMapFor(culture); foreach (string translatedText in textMap.Values) { charSet.UnionWith(translatedText); } } } string charactersString = new String(charSet.ToArray()); var bakedFontConfigurations = AssetDatabaseUtil.AllAssetsOfType <BakedLocalizedFontConfiguration>(); if (bakedFontConfigurations.Count <= 0) { Debug.LogWarning("Cannot bake used localization characters without any BakedLocalizedFontConfigurations in the project!"); return; } foreach (var config in bakedFontConfigurations) { // No need to bake a font that already contains all the characters if (TMP_FontAssetUtil.DoesFontContainAllCharacters(config.OutputFontAsset, charactersString)) { continue; } string outputFilePath = AssetDatabase.GetAssetPath(config.OutputFontAsset); TMPFontAssetBaker.Bake(config.Font, config.useAutoSizing, config.FontSize, config.CharacterPadding, config.FontPackingMode, config.AtlasWidth, config.AtlasHeight, config.FontStyle, config.FontStyleMod, config.FontRenderMode, charactersString, outputFilePath); } }