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

Commit 737c744

Browse files
committed
Make sure that PostProcessStrippingConfig asset always exists
1 parent 2c04d49 commit 737c744

File tree

1 file changed

+29
-13
lines changed

1 file changed

+29
-13
lines changed

PostProcessing/Editor/PostProcessResourceStripper.cs

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ namespace UnityEditor.Rendering.PostProcessing
88
{
99
public sealed class PostProcessResourceStripper : ScriptableObject
1010
{
11+
public const string DefaultStrippingConfigAssetPath = "Assets/PostProcessStrippingConfig.asset";
12+
13+
1114
private PostProcessStrippingConfig stripping;
1215
private PostProcessStrippingConfig defaultConfig;
1316

@@ -32,7 +35,6 @@ public static PostProcessResourceStripper instance
3235
void Awake()
3336
{
3437
SceneManager.sceneLoaded += OnSceneLoaded;
35-
3638
}
3739

3840
void OnDestroy()
@@ -68,22 +70,35 @@ static private void StripDebugShaders(PostProcessResources resources)
6870
resources.computeShaders.vectorscope = null;
6971
}
7072

71-
private void LazyInitStrippingConfig()
73+
static private string FindPostProcessStrippingConfigGUID()
7274
{
73-
if (stripping != null)
74-
return;
75-
7675
var guids = AssetDatabase.FindAssets("t:PostProcessStrippingConfig", null);
7776
if (guids.Length > 0)
78-
{
79-
stripping = (PostProcessStrippingConfig) AssetDatabase.LoadAssetAtPath(AssetDatabase.GUIDToAssetPath(guids[0]), typeof(PostProcessStrippingConfig));
80-
}
77+
return guids[0];
8178
else
79+
return null;
80+
}
81+
82+
static public void EnsurePostProcessStrippingConfigAssetExists()
83+
{
84+
var guid = FindPostProcessStrippingConfigGUID();
85+
if (guid != null)
86+
return;
87+
88+
AssetDatabase.CreateAsset(CreateInstance<PostProcessStrippingConfig>(), DefaultStrippingConfigAssetPath);
89+
AssetDatabase.SaveAssets();
90+
AssetDatabase.Refresh();
91+
}
92+
93+
private void LazyLoadStrippingConfig()
94+
{
95+
if (stripping != null)
96+
return;
97+
98+
var guid = FindPostProcessStrippingConfigGUID();
99+
if (guid != null)
82100
{
83-
// Create a new config asset
84-
AssetDatabase.CreateAsset(defaultConfig, "Assets/PostProcessStrippingConfig.asset");
85-
AssetDatabase.SaveAssets();
86-
AssetDatabase.Refresh();
101+
stripping = (PostProcessStrippingConfig) AssetDatabase.LoadAssetAtPath(AssetDatabase.GUIDToAssetPath(guid), typeof(PostProcessStrippingConfig));
87102
}
88103

89104
if (stripping == null)
@@ -115,7 +130,7 @@ private void Apply(BuildTarget target, PostProcessResources resources)
115130
if (defaultConfig == null)
116131
return;
117132

118-
LazyInitStrippingConfig();
133+
LazyLoadStrippingConfig();
119134
if (stripping == null)
120135
return;
121136

@@ -230,6 +245,7 @@ public void OnPreprocessBuild(BuildTarget target, string path)
230245
public class SetupStripping {
231246
static SetupStripping()
232247
{
248+
PostProcessResourceStripper.EnsurePostProcessStrippingConfigAssetExists();
233249
PostProcessResourcesFactory.Init(PostProcessResourceStripper.Strip);
234250
}
235251
}

0 commit comments

Comments
 (0)