-
Notifications
You must be signed in to change notification settings - Fork 0
/
AssetBundleUtilities.cs
61 lines (54 loc) · 2.25 KB
/
AssetBundleUtilities.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
using UnityEngine;
namespace ExpeditionTakeoff;
public static class AssetBundleUtilities
{
public static void ReplaceShaders(GameObject prefab)
{
foreach (var renderer in prefab.GetComponentsInChildren<Renderer>(true))
{
foreach (var material in renderer.sharedMaterials)
{
if (material == null) continue;
var replacementShader = Shader.Find(material.shader.name);
if (replacementShader == null) continue;
// preserve override tag and render queue (for Standard shader)
// keywords and properties are already preserved
if (material.renderQueue != material.shader.renderQueue)
{
var renderType = material.GetTag("RenderType", false);
var renderQueue = material.renderQueue;
material.shader = replacementShader;
material.SetOverrideTag("RenderType", renderType);
material.renderQueue = renderQueue;
}
else
{
material.shader = replacementShader;
}
}
}
foreach (var trenderer in prefab.GetComponentsInChildren<TessellatedRenderer>(true))
{
foreach (var material in trenderer.sharedMaterials)
{
if (material == null) continue;
var replacementShader = Shader.Find(material.shader.name);
if (replacementShader == null) continue;
// preserve override tag and render queue (for Standard shader)
// keywords and properties are already preserved
if (material.renderQueue != material.shader.renderQueue)
{
var renderType = material.GetTag("RenderType", false);
var renderQueue = material.renderQueue;
material.shader = replacementShader;
material.SetOverrideTag("RenderType", renderType);
material.renderQueue = renderQueue;
}
else
{
material.shader = replacementShader;
}
}
}
}
}