2022-02-18 04:58:28 +00:00
|
|
|
|
using UnityEngine;
|
2022-02-18 01:31:38 +00:00
|
|
|
|
|
2022-02-27 12:40:44 +00:00
|
|
|
|
namespace QSB.PlayerBodySetup.Remote
|
2022-02-18 01:31:38 +00:00
|
|
|
|
{
|
2022-02-27 12:40:44 +00:00
|
|
|
|
public static class ShaderReplacer
|
2022-02-18 01:31:38 +00:00
|
|
|
|
{
|
2022-02-27 12:40:44 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// the materials on the prefabs have the exact same name as the ones in game.
|
|
|
|
|
/// if we just use Shader.Find, we can get the in-game ones instead of the prefab ones,
|
|
|
|
|
/// and replace the prefab ones with the in-game ones.
|
|
|
|
|
/// i am amazed that this works, and i hope it isn't super brittle.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static void ReplaceShaders(GameObject prefab)
|
2022-02-18 01:31:38 +00:00
|
|
|
|
{
|
2022-02-27 12:40:44 +00:00
|
|
|
|
foreach (var renderer in prefab.GetComponentsInChildren<Renderer>(true))
|
2022-02-18 01:37:56 +00:00
|
|
|
|
{
|
2022-02-27 12:40:44 +00:00
|
|
|
|
foreach (var material in renderer.sharedMaterials)
|
2022-02-18 01:37:56 +00:00
|
|
|
|
{
|
2022-02-27 12:40:44 +00:00
|
|
|
|
if (material == null)
|
|
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2022-02-25 06:04:54 +00:00
|
|
|
|
|
2022-02-27 12:40:44 +00:00
|
|
|
|
material.shader = Shader.Find(material.shader.name);
|
|
|
|
|
}
|
2022-02-18 01:37:56 +00:00
|
|
|
|
}
|
2022-02-18 01:31:38 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2022-02-25 06:04:54 +00:00
|
|
|
|
}
|