2024-10-02 23:28:33 +08:00
|
|
|
|
using System;
|
2024-10-03 20:02:10 +08:00
|
|
|
|
using System.Collections.Generic;
|
2024-10-02 23:28:33 +08:00
|
|
|
|
using System.IO;
|
2024-10-03 20:02:10 +08:00
|
|
|
|
using System.Linq;
|
2024-10-02 23:28:33 +08:00
|
|
|
|
using HarmonyLib;
|
|
|
|
|
using MelonLoader;
|
|
|
|
|
using TMPro;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
using UnityEngine.TextCore.LowLevel;
|
|
|
|
|
|
|
|
|
|
namespace AquaMai.UX;
|
|
|
|
|
|
|
|
|
|
public class CustomFont
|
|
|
|
|
{
|
2024-10-03 20:02:10 +08:00
|
|
|
|
private static Font font;
|
2024-10-02 23:28:33 +08:00
|
|
|
|
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;
|
|
|
|
|
|
2024-10-03 20:02:10 +08:00
|
|
|
|
font = new Font(fontPath);
|
2024-10-02 23:28:33 +08:00
|
|
|
|
fontAsset = TMP_FontAsset.CreateFontAsset(font, 90, 9, GlyphRenderMode.SDFAA, 8192, 8192);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HarmonyPatch(typeof(TextMeshProUGUI), "Awake")]
|
|
|
|
|
[HarmonyPostfix]
|
|
|
|
|
public static void PostFix(TextMeshProUGUI __instance)
|
|
|
|
|
{
|
2024-10-03 20:02:10 +08:00
|
|
|
|
if (font is null) return;
|
2024-10-02 23:28:33 +08:00
|
|
|
|
# if DEBUG
|
|
|
|
|
MelonLogger.Msg($"{__instance.font.name} {__instance.text}");
|
|
|
|
|
# endif
|
2024-10-03 20:02:10 +08:00
|
|
|
|
|
|
|
|
|
var materialOrigin = __instance.fontMaterial;
|
|
|
|
|
var materialSharedOrigin = __instance.fontSharedMaterial;
|
2024-10-02 23:28:33 +08:00
|
|
|
|
__instance.font = fontAsset;
|
2024-10-03 20:02:10 +08:00
|
|
|
|
# if DEBUG
|
|
|
|
|
MelonLogger.Msg($"shaderKeywords {materialOrigin.shaderKeywords.Join()} {__instance.fontMaterial.shaderKeywords.Join()}");
|
|
|
|
|
# endif
|
|
|
|
|
// __instance.fontSharedMaterial = materialSharedOrigin;
|
|
|
|
|
|
|
|
|
|
// 这样之后该有描边的地方整个字后面都是阴影,它不知道哪里是边
|
|
|
|
|
// materialOrigin.mainTexture = __instance.fontMaterial.mainTexture;
|
|
|
|
|
// materialOrigin.mainTextureOffset = __instance.fontMaterial.mainTextureOffset;
|
|
|
|
|
// materialOrigin.mainTextureScale = __instance.fontMaterial.mainTextureScale;
|
|
|
|
|
// __instance.fontMaterial.CopyPropertiesFromMaterial(materialOrigin);
|
|
|
|
|
|
|
|
|
|
// 这样了之后有描边了,但是描边很细
|
|
|
|
|
// __instance.fontMaterial.shader = materialOrigin.shader;
|
|
|
|
|
foreach (var keyword in materialOrigin.shaderKeywords)
|
|
|
|
|
{
|
|
|
|
|
__instance.fontMaterial.EnableKeyword(keyword);
|
|
|
|
|
}
|
|
|
|
|
// __instance.fontMaterial.globalIlluminationFlags = materialOrigin.globalIlluminationFlags;
|
|
|
|
|
|
|
|
|
|
// 原来是 underlay,但是复制这三个属性之后就又变成整个字后面都是阴影了
|
|
|
|
|
// __instance.fontMaterial.SetFloat(ShaderUtilities.ID_UnderlayOffsetY, materialOrigin.GetFloat(ShaderUtilities.ID_UnderlayOffsetY));
|
|
|
|
|
// __instance.fontMaterial.SetFloat(ShaderUtilities.ID_UnderlayOffsetX, materialOrigin.GetFloat(ShaderUtilities.ID_UnderlayOffsetX));
|
|
|
|
|
// __instance.fontMaterial.SetFloat(ShaderUtilities.ID_UnderlayDilate, materialOrigin.GetFloat(ShaderUtilities.ID_UnderlayDilate));
|
|
|
|
|
|
|
|
|
|
// if(materialOrigin.shaderKeywords.Contains(ShaderUtilities.Keyword_Underlay))
|
|
|
|
|
// {
|
|
|
|
|
// __instance.fontMaterial.EnableKeyword(ShaderUtilities.Keyword_Glow);
|
|
|
|
|
// __instance.fontMaterial.SetFloat(ShaderUtilities.ID_GlowOuter, .5f);
|
|
|
|
|
// // __instance.fontMaterial.SetFloat(ShaderUtilities.ID_UnderlayOffsetX, materialOrigin.GetFloat(ShaderUtilities.ID_UnderlayOffsetX));
|
|
|
|
|
// }
|
|
|
|
|
|
2024-10-02 23:28:33 +08:00
|
|
|
|
}
|
|
|
|
|
}
|