中文
问题背景
在使用 XUnity.AutoTranslator 的过程中,翻译文本经常因为各种原因显示为方块字(▯)。常见的解决办法是下载或自制一个兼容性更好的字体,但这种方法并不总是有效。我最近就遇到了一个案例:在一个较新版本的 IL2CPP Unity 游戏(Unity 6000)中,AutoTranslator 调用了新版引擎已不再支持的方法,导致 hook 失败;随后它的 fallback 机制自动改用游戏自身的字体资源来渲染翻译文本。这意味着无论配置哪种 TMP 字体,都无法被正常加载到游戏中,最终屏幕上出现大量方块字。
解决方案
针对这个问题,我编写了一个 BepInEx 插件:它从系统字体创建一个动态 TMP 字体资源,并持续将场景中所有 TMP 文本强制替换为这个字体。由于替换是直接强制的,即使 AutoTranslator fallback 到游戏自身字体,最终渲染的仍然是我这个插件替换进来的字体,而不是游戏原本的字体。这样一来,无论方块字由何种原因引起,都能得到解决。
唯一的缺点是:游戏中原本各具特色的字体都会被替换成单调的系统字体,界面风格会有一定损失。
发布信息
插件已发布在 GitHub:https://github.com/qkkshbd/XUnity-Fonts-Loader
注意事项:
- 目前插件只有 IL2CPP 版本;
- 用于 Mono 游戏可能无法正常工作,我尚未对此进行过测试。
English
Background
When using XUnity.AutoTranslator, translated text often shows up as tofu characters (▯) for a variety of reasons. The common workaround is to download or create a font with better compatibility, but this approach does not always work. I recently ran into a typical case: in a fairly recent IL2CPP Unity game (Unity 6000), AutoTranslator called an API that is no longer supported by the new engine, which caused the hook to fail. Its fallback mechanism then automatically switched to the game's own font resources to render the translated text. As a result, no TMP font configuration could be loaded properly, and the game displayed tofu characters everywhere.
Solution
To address this, I wrote a BepInEx plugin that creates a dynamic TMP font asset from an OS font and continuously forces every TMP text in the scene to use it. Because the replacement is enforced directly, even when AutoTranslator falls back to the game's built-in fonts, the text is still rendered with the font injected by this plugin rather than the game's original font. This resolves tofu characters regardless of the underlying cause.
The trade-off is that all of the game's distinctive fonts are replaced with a plain system font, which affects the visual style of the UI.
Availability
The plugin is published on GitHub: https://github.com/qkkshbd/XUnity-Fonts-Loader
Notes:
- Only an IL2CPP version is currently available.
- It may not work properly on Mono games; this has not been tested.
中文
问题背景
在使用 XUnity.AutoTranslator 的过程中,翻译文本经常因为各种原因显示为方块字(▯)。常见的解决办法是下载或自制一个兼容性更好的字体,但这种方法并不总是有效。我最近就遇到了一个案例:在一个较新版本的 IL2CPP Unity 游戏(Unity 6000)中,AutoTranslator 调用了新版引擎已不再支持的方法,导致 hook 失败;随后它的 fallback 机制自动改用游戏自身的字体资源来渲染翻译文本。这意味着无论配置哪种 TMP 字体,都无法被正常加载到游戏中,最终屏幕上出现大量方块字。
解决方案
针对这个问题,我编写了一个 BepInEx 插件:它从系统字体创建一个动态 TMP 字体资源,并持续将场景中所有 TMP 文本强制替换为这个字体。由于替换是直接强制的,即使 AutoTranslator fallback 到游戏自身字体,最终渲染的仍然是我这个插件替换进来的字体,而不是游戏原本的字体。这样一来,无论方块字由何种原因引起,都能得到解决。
唯一的缺点是:游戏中原本各具特色的字体都会被替换成单调的系统字体,界面风格会有一定损失。
发布信息
插件已发布在 GitHub:https://github.com/qkkshbd/XUnity-Fonts-Loader
注意事项:
English
Background
When using XUnity.AutoTranslator, translated text often shows up as tofu characters (▯) for a variety of reasons. The common workaround is to download or create a font with better compatibility, but this approach does not always work. I recently ran into a typical case: in a fairly recent IL2CPP Unity game (Unity 6000), AutoTranslator called an API that is no longer supported by the new engine, which caused the hook to fail. Its fallback mechanism then automatically switched to the game's own font resources to render the translated text. As a result, no TMP font configuration could be loaded properly, and the game displayed tofu characters everywhere.
Solution
To address this, I wrote a BepInEx plugin that creates a dynamic TMP font asset from an OS font and continuously forces every TMP text in the scene to use it. Because the replacement is enforced directly, even when AutoTranslator falls back to the game's built-in fonts, the text is still rendered with the font injected by this plugin rather than the game's original font. This resolves tofu characters regardless of the underlying cause.
The trade-off is that all of the game's distinctive fonts are replaced with a plain system font, which affects the visual style of the UI.
Availability
The plugin is published on GitHub: https://github.com/qkkshbd/XUnity-Fonts-Loader
Notes: