@@ -11,6 +11,9 @@ public sealed class PostProcessResourceStripper : ScriptableObject
11
11
[ SerializeField ] private PostProcessResources unstrippedResources ;
12
12
[ SerializeField ] private PostProcessStrippingConfig stripping ;
13
13
14
+ public const string DefaultStrippingConfigAssetPath = "Assets/PostProcessStrippingConfig.asset" ;
15
+ bool enabled = true ;
16
+
14
17
static PostProcessResourceStripper s_Instance ;
15
18
16
19
public static PostProcessResourceStripper instance
@@ -27,6 +30,45 @@ public static PostProcessResourceStripper instance
27
30
}
28
31
}
29
32
33
+ static private string FindPostProcessStrippingConfigGUID ( )
34
+ {
35
+ var guids = AssetDatabase . FindAssets ( "t:PostProcessStrippingConfig" , null ) ;
36
+ if ( guids . Length > 0 )
37
+ return guids [ 0 ] ;
38
+ else
39
+ return null ;
40
+ }
41
+
42
+ static public string EnsurePostProcessStrippingConfigAssetExists ( )
43
+ {
44
+ var guid = FindPostProcessStrippingConfigGUID ( ) ;
45
+ if ( guid != null )
46
+ return guid ;
47
+
48
+ bool wasEnabled = instance . enabled ;
49
+ instance . enabled = false ;
50
+ AssetDatabase . CreateAsset ( CreateInstance < PostProcessStrippingConfig > ( ) , DefaultStrippingConfigAssetPath ) ;
51
+ AssetDatabase . SaveAssets ( ) ;
52
+ AssetDatabase . Refresh ( ) ;
53
+ instance . enabled = wasEnabled ;
54
+ return FindPostProcessStrippingConfigGUID ( ) ;
55
+ }
56
+
57
+ private void LazyLoadStrippingConfig ( )
58
+ {
59
+ if ( stripping != null )
60
+ return ;
61
+
62
+ var guid = EnsurePostProcessStrippingConfigAssetExists ( ) ;
63
+ if ( guid != null )
64
+ {
65
+ bool wasEnabled = instance . enabled ;
66
+ instance . enabled = false ;
67
+ stripping = ( PostProcessStrippingConfig ) AssetDatabase . LoadAssetAtPath ( AssetDatabase . GUIDToAssetPath ( guid ) , typeof ( PostProcessStrippingConfig ) ) ;
68
+ instance . enabled = wasEnabled ;
69
+ }
70
+ }
71
+
30
72
void OnDestroy ( )
31
73
{
32
74
unstrippedResources . changeHandler = null ;
@@ -62,12 +104,16 @@ private void StripDebugShaders()
62
104
63
105
private void Apply ( BuildTarget target )
64
106
{
107
+ if ( ! enabled )
108
+ return ;
109
+
65
110
if ( resources == null )
66
111
return ;
67
112
68
113
if ( unstrippedResources == null )
69
114
return ;
70
115
116
+ LazyLoadStrippingConfig ( ) ;
71
117
if ( stripping == null )
72
118
return ;
73
119
@@ -152,4 +198,14 @@ public void OnPreprocessBuild(BuildTarget target, string path)
152
198
#endif
153
199
}
154
200
#endif
201
+
202
+
203
+ [ InitializeOnLoad ]
204
+ public class SetupStrippingConfig {
205
+ static SetupStrippingConfig ( )
206
+ {
207
+ PostProcessResourceStripper . EnsurePostProcessStrippingConfigAssetExists ( ) ;
208
+ }
209
+ }
210
+
155
211
}
0 commit comments