From f55b591dd9899724c1372e4100f306540201f47d Mon Sep 17 00:00:00 2001 From: SFGrenade <25555417+SFGrenade@users.noreply.github.com> Date: Sun, 20 Oct 2024 20:41:01 +0200 Subject: [PATCH] revert dynamic shader name stuff - unity can't be trusted bump version --- SFCore.csproj | 2 +- src/MonoBehaviours/SpritePatcher.cs | 9 ++++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/SFCore.csproj b/SFCore.csproj index bdbf093..543568c 100644 --- a/SFCore.csproj +++ b/SFCore.csproj @@ -7,7 +7,7 @@ SFCore A Hollow Knight Mod Library Copyright © SFGrenade 2024 - 1.5.12.3 + 1.5.12.4 $(AssemblyVersion) false true diff --git a/src/MonoBehaviours/SpritePatcher.cs b/src/MonoBehaviours/SpritePatcher.cs index d251f6c..7d9a360 100644 --- a/src/MonoBehaviours/SpritePatcher.cs +++ b/src/MonoBehaviours/SpritePatcher.cs @@ -8,6 +8,8 @@ namespace SFCore.MonoBehaviours; /// class SpritePatcher : MonoBehaviour { + private static Dictionary _materials = new Dictionary(); + /// /// Shader to apply to all SpriteRenderers on this GameObject and children /// @@ -22,10 +24,15 @@ class SpritePatcher : MonoBehaviour /// public void Start() { + if (!_materials.ContainsKey(shader)) + { + var mat = new Material(Shader.Find(shader)); + _materials.Add(shader, mat); + } foreach (SpriteRenderer sr in gameObject.GetComponentsInChildren(true)) { sr.gameObject.transform.localScale *= Scale; - sr.material.shader = Shader.Find(sr.material.shader.name); + sr.material = _materials[shader]; } } } \ No newline at end of file