1
1
using System ;
2
2
using UnityEditor . Build ;
3
3
using UnityEngine ;
4
- using UnityEngine . SceneManagement ;
5
4
using UnityEngine . Rendering . PostProcessing ;
6
5
7
6
namespace UnityEditor . Rendering . PostProcessing
8
7
{
9
8
public sealed class PostProcessResourceStripper : ScriptableObject
10
9
{
11
- private PostProcessStrippingConfig stripping ;
12
- private PostProcessStrippingConfig defaultConfig ;
13
-
10
+ [ SerializeField ] private PostProcessResources resources ;
14
11
[ SerializeField ] private PostProcessResources unstrippedResources ;
12
+ [ SerializeField ] private PostProcessStrippingConfig stripping ;
15
13
16
14
static PostProcessResourceStripper s_Instance ;
17
15
@@ -22,25 +20,19 @@ public static PostProcessResourceStripper instance
22
20
if ( s_Instance == null )
23
21
{
24
22
s_Instance = CreateInstance < PostProcessResourceStripper > ( ) ;
25
- s_Instance . defaultConfig = CreateInstance < PostProcessStrippingConfig > ( ) ;
23
+ s_Instance . unstrippedResources . changeHandler = Update ;
26
24
}
27
25
28
26
return s_Instance ;
29
27
}
30
28
}
31
29
32
- void Awake ( )
33
- {
34
- SceneManager . sceneLoaded += OnSceneLoaded ;
35
-
36
- }
37
-
38
30
void OnDestroy ( )
39
31
{
40
- SceneManager . sceneLoaded -= OnSceneLoaded ;
32
+ unstrippedResources . changeHandler = null ;
41
33
}
42
34
43
- static private void StripMultiScaleAO ( PostProcessResources resources )
35
+ private void StripMultiScaleAO ( )
44
36
{
45
37
resources . computeShaders . multiScaleAODownsample1 = null ;
46
38
resources . computeShaders . multiScaleAODownsample2 = null ;
@@ -49,13 +41,13 @@ static private void StripMultiScaleAO(PostProcessResources resources)
49
41
resources . shaders . multiScaleAO = null ;
50
42
}
51
43
52
- static private void StripScreenSpaceReflections ( PostProcessResources resources )
44
+ private void StripScreenSpaceReflections ( )
53
45
{
54
46
resources . shaders . screenSpaceReflections = null ;
55
47
resources . computeShaders . gaussianDownsample = null ;
56
48
}
57
49
58
- static private void StripDebugShaders ( PostProcessResources resources )
50
+ private void StripDebugShaders ( )
59
51
{
60
52
resources . shaders . lightMeter = null ;
61
53
resources . shaders . gammaHistogram = null ;
@@ -68,61 +60,15 @@ static private void StripDebugShaders(PostProcessResources resources)
68
60
resources . computeShaders . vectorscope = null ;
69
61
}
70
62
71
- private void LazyInitStrippingConfig ( )
72
- {
73
- if ( stripping != null )
74
- return ;
75
-
76
- var guids = AssetDatabase . FindAssets ( "t:PostProcessStrippingConfig" , null ) ;
77
- if ( guids . Length > 0 )
78
- {
79
- stripping = ( PostProcessStrippingConfig ) AssetDatabase . LoadAssetAtPath ( AssetDatabase . GUIDToAssetPath ( guids [ 0 ] ) , typeof ( PostProcessStrippingConfig ) ) ;
80
- }
81
- else
82
- {
83
- // Create a new config asset
84
- AssetDatabase . CreateAsset ( defaultConfig , "Assets/PostProcessStrippingConfig.asset" ) ;
85
- AssetDatabase . SaveAssets ( ) ;
86
- AssetDatabase . Refresh ( ) ;
87
- }
88
-
89
- if ( stripping == null )
90
- stripping = defaultConfig ;
91
- }
92
-
93
- private void SetConfig ( PostProcessStrippingConfig config )
94
- {
95
- if ( config == stripping )
96
- return ;
97
-
98
- if ( defaultConfig == null )
99
- return ;
100
-
101
- if ( config == defaultConfig )
102
- return ;
103
-
104
- if ( config == null )
105
- {
106
- stripping = defaultConfig ;
107
- return ;
108
- }
109
-
110
- stripping = config ;
111
- }
112
-
113
- private void Apply ( BuildTarget target , PostProcessResources resources )
63
+ private void Apply ( BuildTarget target )
114
64
{
115
- if ( defaultConfig == null )
116
- return ;
117
-
118
- LazyInitStrippingConfig ( ) ;
119
- if ( stripping == null )
65
+ if ( resources == null )
120
66
return ;
121
67
122
68
if ( unstrippedResources == null )
123
69
return ;
124
70
125
- if ( resources == null )
71
+ if ( stripping == null )
126
72
return ;
127
73
128
74
resources . computeShaders = unstrippedResources . computeShaders . Clone ( ) ;
@@ -132,26 +78,26 @@ private void Apply(BuildTarget target, PostProcessResources resources)
132
78
if ( stripping . stripUnsupportedShaders &&
133
79
( target == BuildTarget . Android || target == BuildTarget . iOS || target == BuildTarget . tvOS ) )
134
80
{
135
- StripMultiScaleAO ( resources ) ;
81
+ StripMultiScaleAO ( ) ;
136
82
}
137
83
138
84
if ( stripping . stripDebugShaders )
139
85
{
140
- StripDebugShaders ( resources ) ;
86
+ StripDebugShaders ( ) ;
141
87
}
142
88
143
89
if ( stripping . stripComputeShaders )
144
90
{
145
91
resources . computeShaders = new PostProcessResources . ComputeShaders ( ) ;
146
92
resources . shaders . autoExposure = null ;
147
- StripScreenSpaceReflections ( resources ) ;
148
- StripMultiScaleAO ( resources ) ;
149
- StripDebugShaders ( resources ) ;
93
+ StripScreenSpaceReflections ( ) ;
94
+ StripMultiScaleAO ( ) ;
95
+ StripDebugShaders ( ) ;
150
96
}
151
97
152
98
if ( stripping . stripUnsupportedShaders && ! RuntimeUtilities . supportsDeferredShading )
153
99
{
154
- StripScreenSpaceReflections ( resources ) ;
100
+ StripScreenSpaceReflections ( ) ;
155
101
resources . shaders . deferredFog = null ;
156
102
if ( ! RuntimeUtilities . supportsDepthNormals )
157
103
resources . shaders . scalableAO = null ;
@@ -166,35 +112,14 @@ private void Apply(BuildTarget target, PostProcessResources resources)
166
112
}
167
113
}
168
114
169
- void OnSceneLoaded ( Scene scene , LoadSceneMode mode )
115
+ public static void Update ( )
170
116
{
171
- StripAll ( ) ;
117
+ Update ( EditorUserBuildSettings . activeBuildTarget ) ;
172
118
}
173
119
174
- public static void Strip ( PostProcessResources resources )
120
+ public static void Update ( BuildTarget target )
175
121
{
176
- instance . Apply ( EditorUserBuildSettings . activeBuildTarget , resources ) ;
177
- }
178
-
179
- public static void StripAll ( BuildTarget target )
180
- {
181
- var allResources = PostProcessResourcesFactory . AllResources ( ) ;
182
- if ( allResources == null )
183
- return ;
184
-
185
- foreach ( var resources in allResources )
186
- instance . Apply ( EditorUserBuildSettings . activeBuildTarget , resources ) ;
187
- }
188
-
189
- public static void StripAll ( )
190
- {
191
- StripAll ( EditorUserBuildSettings . activeBuildTarget ) ;
192
- }
193
-
194
- public static void StripAll ( PostProcessStrippingConfig config )
195
- {
196
- instance . SetConfig ( config ) ;
197
- StripAll ( EditorUserBuildSettings . activeBuildTarget ) ;
122
+ instance . Apply ( EditorUserBuildSettings . activeBuildTarget ) ;
198
123
}
199
124
}
200
125
@@ -204,7 +129,7 @@ sealed class UpdateStrippingOnBuildTargetChange : IActiveBuildTargetChanged
204
129
public int callbackOrder { get { return 0 ; } }
205
130
public void OnActiveBuildTargetChanged ( BuildTarget previousTarget , BuildTarget newTarget )
206
131
{
207
- PostProcessResourceStripper . StripAll ( newTarget ) ;
132
+ PostProcessResourceStripper . Update ( newTarget ) ;
208
133
}
209
134
}
210
135
@@ -215,23 +140,15 @@ sealed class UpdateStrippingBeforeBuild : IPreprocessBuild
215
140
#if UNITY_2018_1_OR_NEWER
216
141
public void OnPreprocessBuild ( Build . Reporting . BuildReport report )
217
142
{
218
- PostProcessResourceStripper . StripAll ( report . summary . platform ) ;
143
+ PostProcessResourceStripper . Update ( report . summary . platform ) ;
219
144
}
220
145
#else
221
146
public void OnPreprocessBuild ( BuildTarget target , string path )
222
147
{
223
- PostProcessResourceStripper . StripAll ( target ) ;
148
+ PostProcessResourceStripper . Update ( target ) ;
224
149
}
225
150
#endif
226
151
}
227
152
#endif
228
153
229
- [ InitializeOnLoad ]
230
- public class SetupStripping {
231
- static SetupStripping ( )
232
- {
233
- PostProcessResourcesFactory . Init ( PostProcessResourceStripper . Strip ) ;
234
- }
235
- }
236
-
237
154
}
0 commit comments