Skip to content

Commit

Permalink
option to preserve render queue when replacing shader
Browse files Browse the repository at this point in the history
  • Loading branch information
al2me6 committed Jul 23, 2024
1 parent 7ab87f6 commit 6d2de80
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion Source/MaterialDef.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, bool> keywords;
public Dictionary<string, float> floats;
public Dictionary<string, Color> colors;
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 6d2de80

Please sign in to comment.