有一种字体 - Handwritten_Institute.ttf
(也是Handwritten_Institute.asset
SDF 格式)。您需要将其导入到 MelonLoader 上的 mod 中。经过无数次的尝试Resources.Load
,很明显这是没有意义的。之后,AssetBundles 出现了。但即使在这里也有一个错误During invoking native->managed trampoline
(但文件在那里),也有人尝试通过 WWW 和 UnityWebRequest 下载 Bundles。接下来,找到“解决方案”后,将 ttf 字体加载到 TextMeshPro 类中。班级已申请,但没有任何变化。
using HarmonyLib;
using Il2CppTMPro;
using UnityEngine;
using PVZ_Hyper_Fusion.AssetStore; // StringStore.TranslateText
namespace PVZ_Hyper_Fusion.Patches
{
[HarmonyPatch(typeof(TextMeshPro))]
public static class TextMeshPro_Patch
{
[HarmonyPatch(nameof(TextMeshProUGUI.OnEnable))]
[HarmonyPostfix]
private static void OnEnable(TextMeshProUGUI __instance)
{
TMP_FontAsset tmpro = Resources.Load<TMP_FontAsset>(""); //если оставить тут пустоту, то он возьмет стандартный шрифт, и это было оставлено на TODO
__instance.font = tmpro;
if (!string.IsNullOrEmpty(__instance.text))
{
__instance.autoSizeTextContainer = true;
__instance.ForceMeshUpdate();
__instance.SetAllDirty();
__instance.text = StringStore.TranslateText(__instance.text);
}
}
}
}
UPD:还有一个测试
Font start_font = Font.CreateDynamicFontFromOSFont(Font.GetOSInstalledFontNames()[0], 23);
,但同时也发出了During invoking native->managed trampoline
UPD 2:AssetDatabase.LoadAssetAtPath
仅在编辑器中有效