mirror of
https://github.com/MewoLab/AquaDX.git
synced 2026-02-12 15:47:58 +08:00
[+] Some font features
This commit is contained in:
36
AquaMai/UX/CustomFont.cs
Normal file
36
AquaMai/UX/CustomFont.cs
Normal file
@@ -0,0 +1,36 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using HarmonyLib;
|
||||
using MelonLoader;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.TextCore.LowLevel;
|
||||
|
||||
namespace AquaMai.UX;
|
||||
|
||||
public class CustomFont
|
||||
{
|
||||
private static TMP_FontAsset fontAsset;
|
||||
|
||||
public static void DoCustomPatch(HarmonyLib.Harmony h)
|
||||
{
|
||||
var fontPath = Path.Combine(Environment.CurrentDirectory, "LocalAssets", "font.ttf");
|
||||
if (!File.Exists(fontPath)) return;
|
||||
|
||||
var font = new Font(fontPath);
|
||||
|
||||
// 不设置成 8192 的话,贴图会用完,剩下的字显示不出来
|
||||
fontAsset = TMP_FontAsset.CreateFontAsset(font, 90, 9, GlyphRenderMode.SDFAA, 8192, 8192);
|
||||
}
|
||||
|
||||
[HarmonyPatch(typeof(TextMeshProUGUI), "Awake")]
|
||||
[HarmonyPostfix]
|
||||
public static void PostFix(TextMeshProUGUI __instance)
|
||||
{
|
||||
if (fontAsset is null) return;
|
||||
# if DEBUG
|
||||
MelonLogger.Msg($"{__instance.font.name} {__instance.text}");
|
||||
# endif
|
||||
__instance.font = fontAsset;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user