From 6d2de80855d02a512f3646cd77f737d63da7f395 Mon Sep 17 00:00:00 2001 From: Alvin Meng Date: Mon, 22 Jul 2024 22:50:01 -0400 Subject: [PATCH] option to preserve render queue when replacing shader --- Source/MaterialDef.cs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/Source/MaterialDef.cs b/Source/MaterialDef.cs index 354f99f..d520b6c 100644 --- a/Source/MaterialDef.cs +++ b/Source/MaterialDef.cs @@ -58,6 +58,8 @@ public class MaterialDef [Persistent(name = "shader")] public string shaderName = null; public Shader shader = null; + [Persistent] public bool preserveRenderQueue = false; + public Dictionary keywords; public Dictionary floats; public Dictionary colors; @@ -132,7 +134,12 @@ static object ParseColor(string value) public void ApplyTo(Material material) { - if (shader != null) material.shader = shader; + if (shader != null) { + // Replacing the shader resets the render queue to the shader's default. + var renderQueue = preserveRenderQueue ? material.renderQueue : -1; + material.shader = shader; + material.renderQueue = renderQueue; + } foreach (var kvp in keywords) { if (kvp.Value) material.EnableKeyword(kvp.Key);