miuu-custom-cosmetic-loader/Patches/MarbleHolderPatches.cs

27 lines
768 B
C#

using HarmonyLib;
using System;
using UnityEngine;
namespace CustomCosmeticLoader.Patches
{
[HarmonyPatch(typeof(MarbleHolder), nameof(MarbleHolder.SetMarble))]
internal class MarbleHolderSetMarblePatch
{
static void Postfix(MarbleHolder __instance, Cosmetic marbleObject)
{
if (!Config.enabled)
return;
if (marbleObject.Id != Config.skinToHijack && Config.skinToHijack != "*")
return;
MeshRenderer[] componentsInChildren = __instance.currentMarble.GetComponentsInChildren<MeshRenderer>();
for (int i = 0; i < componentsInChildren.Length; i++)
{
Material[] materials = componentsInChildren[i].materials;
foreach (Material material in materials)
material.mainTexture = Config.skins[Config.currentSkin];
}
}
}
}