Skip to content
This repository was archived by the owner on Nov 30, 2020. It is now read-only.

Commit 666da9e

Browse files
committed
Reimplement creation of PostProcessStrippingConfig.asset into project.
1 parent aedd699 commit 666da9e

File tree

3 files changed

+56
-10
lines changed

3 files changed

+56
-10
lines changed

PostProcessing/Editor/PostProcessResourceStripper.cs

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ public sealed class PostProcessResourceStripper : ScriptableObject
1111
[SerializeField] private PostProcessResources unstrippedResources;
1212
[SerializeField] private PostProcessStrippingConfig stripping;
1313

14+
public const string DefaultStrippingConfigAssetPath = "Assets/PostProcessStrippingConfig.asset";
15+
bool enabled = true;
16+
1417
static PostProcessResourceStripper s_Instance;
1518

1619
public static PostProcessResourceStripper instance
@@ -27,6 +30,45 @@ public static PostProcessResourceStripper instance
2730
}
2831
}
2932

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+
3072
void OnDestroy()
3173
{
3274
unstrippedResources.changeHandler = null;
@@ -62,12 +104,16 @@ private void StripDebugShaders()
62104

63105
private void Apply(BuildTarget target)
64106
{
107+
if (!enabled)
108+
return;
109+
65110
if (resources == null)
66111
return;
67112

68113
if (unstrippedResources == null)
69114
return;
70115

116+
LazyLoadStrippingConfig();
71117
if (stripping == null)
72118
return;
73119

@@ -152,4 +198,14 @@ public void OnPreprocessBuild(BuildTarget target, string path)
152198
#endif
153199
}
154200
#endif
201+
202+
203+
[InitializeOnLoad]
204+
public class SetupStrippingConfig {
205+
static SetupStrippingConfig()
206+
{
207+
PostProcessResourceStripper.EnsurePostProcessStrippingConfigAssetExists();
208+
}
209+
}
210+
155211
}
-4.11 KB
Binary file not shown.

PostProcessing/PostProcessStrippingConfig.asset.meta

Lines changed: 0 additions & 10 deletions
This file was deleted.

0 commit comments

Comments
 (0)