forked from SixWays/UnityShaderStripper
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathShaderStripperTier.cs
72 lines (65 loc) · 2.59 KB
/
ShaderStripperTier.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
62
63
64
65
66
67
68
69
70
71
72
#if UNITY_EDITOR && UNITY_2018_2_OR_NEWER
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using UnityEngine;
using UnityEngine.Rendering;
using UnityEditor;
using UnityEditor.Rendering;
namespace Sigtrap.Editors.ShaderStripper {
/// <summary>
/// Strips shaders by shader tier.
/// </summary>
[CreateAssetMenu(menuName="Sigtrap/Shader Stripper Tier")]
public class ShaderStripperTier : ShaderStripperBase, ISerializationCallbackReceiver {
[System.Serializable]
struct TierData {
public ShaderCompilerPlatform platform;
[Tooltip("If true, strip Tier1 (Low) variants on this platform.")]
public bool stripTier1;
[Tooltip("If true, strip Tier2 (Med) variants on this platform.")]
public bool stripTier2;
[Tooltip("If true, strip Tier3 (High) variants on this platform.")]
public bool stripTier3;
}
[SerializeField][Tooltip("Tiers to strip per-platform.")]
TierData[] _tiers;
Dictionary<ShaderCompilerPlatform, TierData> _data;
List<ShaderCompilerPlatform> _tempCheckDupes = new List<ShaderCompilerPlatform>();
public void OnAfterDeserialize(){
_data = new Dictionary<ShaderCompilerPlatform, TierData>();
foreach (var t in _tiers){
_data[t.platform] = t;
}
}
public void OnBeforeSerialize(){}
void OnValidate(){
_tempCheckDupes.Clear();
foreach (var t in _tiers){
if (_tempCheckDupes.Contains(t.platform)){
Debug.LogWarning("Cannot have duplicate platforms in ShaderStripperTier settings", this);
} else {
_tempCheckDupes.Add(t.platform);
}
}
}
protected override bool _checkPass {get {return false;}}
protected override bool _checkVariants {get {return true;}}
protected override bool _checkShader {get {return false;}}
protected override bool MatchVariant(ShaderCompilerData variantData){
TierData t;
if (_data.TryGetValue(variantData.shaderCompilerPlatform, out t)){
switch(variantData.graphicsTier){
case GraphicsTier.Tier1:
return t.stripTier1;
case GraphicsTier.Tier2:
return t.stripTier2;
case GraphicsTier.Tier3:
return t.stripTier3;
}
}
return false;
}
}
}
#endif