mirror of
https://github.com/MewoLab/AquaDX.git
synced 2026-02-12 06:07:27 +08:00
[F] Fix text shadow a little bit
This commit is contained in:
@@ -1,5 +1,7 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
using HarmonyLib;
|
using HarmonyLib;
|
||||||
using MelonLoader;
|
using MelonLoader;
|
||||||
using TMPro;
|
using TMPro;
|
||||||
@@ -10,6 +12,7 @@ namespace AquaMai.UX;
|
|||||||
|
|
||||||
public class CustomFont
|
public class CustomFont
|
||||||
{
|
{
|
||||||
|
private static Font font;
|
||||||
private static TMP_FontAsset fontAsset;
|
private static TMP_FontAsset fontAsset;
|
||||||
|
|
||||||
public static void DoCustomPatch(HarmonyLib.Harmony h)
|
public static void DoCustomPatch(HarmonyLib.Harmony h)
|
||||||
@@ -17,9 +20,7 @@ public class CustomFont
|
|||||||
var fontPath = Path.Combine(Environment.CurrentDirectory, "LocalAssets", "font.ttf");
|
var fontPath = Path.Combine(Environment.CurrentDirectory, "LocalAssets", "font.ttf");
|
||||||
if (!File.Exists(fontPath)) return;
|
if (!File.Exists(fontPath)) return;
|
||||||
|
|
||||||
var font = new Font(fontPath);
|
font = new Font(fontPath);
|
||||||
|
|
||||||
// 不设置成 8192 的话,贴图会用完,剩下的字显示不出来
|
|
||||||
fontAsset = TMP_FontAsset.CreateFontAsset(font, 90, 9, GlyphRenderMode.SDFAA, 8192, 8192);
|
fontAsset = TMP_FontAsset.CreateFontAsset(font, 90, 9, GlyphRenderMode.SDFAA, 8192, 8192);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -27,10 +28,44 @@ public class CustomFont
|
|||||||
[HarmonyPostfix]
|
[HarmonyPostfix]
|
||||||
public static void PostFix(TextMeshProUGUI __instance)
|
public static void PostFix(TextMeshProUGUI __instance)
|
||||||
{
|
{
|
||||||
if (fontAsset is null) return;
|
if (font is null) return;
|
||||||
# if DEBUG
|
# if DEBUG
|
||||||
MelonLogger.Msg($"{__instance.font.name} {__instance.text}");
|
MelonLogger.Msg($"{__instance.font.name} {__instance.text}");
|
||||||
# endif
|
# endif
|
||||||
|
|
||||||
|
var materialOrigin = __instance.fontMaterial;
|
||||||
|
var materialSharedOrigin = __instance.fontSharedMaterial;
|
||||||
__instance.font = fontAsset;
|
__instance.font = fontAsset;
|
||||||
|
# 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));
|
||||||
|
// }
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user