miuu-custom-cosmetic-loader/Shared.cs
2023-10-06 20:23:48 -04:00

75 lines
1.6 KiB
C#

using UnityEngine;
namespace CustomCosmeticLoader
{
public static class Shared
{
private static Cosmetic skinToHijack;
public static Cosmetic SkinToHijack
{
get
{
if (skinToHijack != null && skinToHijack.Id != Config.skinNameToHijack)
skinToHijack = null;
if (skinToHijack == null)
{
DetermineSkinToHijack();
if (skinToHijack == null)
{
Shared.Log("Couldn't find skin " + Config.skinNameToHijack + " to hijack");
Config.skinNameToHijack = "Swirl_M";
DetermineSkinToHijack();
}
}
return skinToHijack;
}
}
private static void DetermineSkinToHijack()
{
foreach (Cosmetic skin in CosmeticManager.Skins)
{
if (skin.Id == Config.skinNameToHijack)
{
skinToHijack = skin;
break;
}
}
}
public static void ApplyCustomTexture(GameObject marbleObject, Texture2D skin = null)
{
if (marbleObject == null)
{
Shared.Log("ApplyCustomTexture - marbleObject is null");
return;
}
if (skin == null)
skin = Config.skins[Config.currentSkin];
MeshRenderer[] componentsInChildren = marbleObject.GetComponentsInChildren<MeshRenderer>();
for (int i = 0; i < componentsInChildren.Length; i++)
{
Material[] materials = componentsInChildren[i].materials;
if (materials == null)
continue;
foreach (Material material in materials)
{
if (material == null)
continue;
if (material.mainTexture != null)
material.mainTexture = skin;
}
}
}
public static void Log(string message)
{
message = "[CUSTOM COSMETIC LOADER] " + message;
Debug.Log(message);
}
}
}