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

Commit f0e8156

Browse files
committed
Fix review findings
Made PostProcessResourceStripper a singleton Use CreateInstance to allocate ScriptableObject Also extracted Build handlers to own classes Add implementation for updated IPreprocessBuild in Unity 2018.1
1 parent 838bed7 commit f0e8156

File tree

1 file changed

+44
-15
lines changed

1 file changed

+44
-15
lines changed

PostProcessing/Editor/PostProcessResourceStripper.cs

Lines changed: 44 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,25 @@
66
namespace UnityEditor.Rendering.PostProcessing
77
{
88
public sealed class PostProcessResourceStripper : ScriptableObject
9-
#if UNITY_2017_1_OR_NEWER
10-
, IPreprocessBuild, IActiveBuildTargetChanged
11-
#endif
129
{
13-
public int callbackOrder { get { return 0; } }
10+
[SerializeField] private PostProcessResources resources;
11+
[SerializeField] private PostProcessResources unstrippedResources;
12+
[SerializeField] private PostProcessStrippingConfig stripping;
1413

15-
[SerializeField] PostProcessResources resources;
16-
[SerializeField] PostProcessResources unstrippedResources;
17-
[SerializeField] PostProcessStrippingConfig stripping;
14+
static PostProcessResourceStripper s_Instance;
1815

19-
void Awake()
16+
public static PostProcessResourceStripper instance
2017
{
21-
unstrippedResources.changeHandler = Update;
18+
get
19+
{
20+
if (s_Instance == null)
21+
{
22+
s_Instance = CreateInstance<PostProcessResourceStripper>();
23+
s_Instance.unstrippedResources.changeHandler = Update;
24+
}
25+
26+
return s_Instance;
27+
}
2228
}
2329

2430
void OnDestroy()
@@ -106,20 +112,43 @@ private void Apply(BuildTarget target)
106112
}
107113
}
108114

109-
public void OnPreprocessBuild(BuildTarget target, string path)
115+
public static void Update()
116+
{
117+
Update(EditorUserBuildSettings.activeBuildTarget);
118+
}
119+
120+
public static void Update(BuildTarget target)
110121
{
111-
Apply(target);
122+
instance.Apply(EditorUserBuildSettings.activeBuildTarget);
112123
}
124+
}
113125

126+
#if UNITY_2017_1_OR_NEWER
127+
sealed class UpdateStrippingOnBuildTargetChange : IActiveBuildTargetChanged
128+
{
129+
public int callbackOrder { get { return 0; } }
114130
public void OnActiveBuildTargetChanged(BuildTarget previousTarget, BuildTarget newTarget)
115131
{
116-
Apply(newTarget);
132+
PostProcessResourceStripper.Update(newTarget);
117133
}
134+
}
118135

119-
public static void Update()
136+
sealed class UpdateStrippingBeforeBuild : IPreprocessBuild
137+
{
138+
public int callbackOrder { get { return 0; } }
139+
140+
#if UNITY_2018_1_OR_NEWER
141+
public void OnPreprocessBuild(Build.Reporting.BuildReport report)
142+
{
143+
PostProcessResourceStripper.Update(report.summary.platform);
144+
}
145+
#else
146+
public void OnPreprocessBuild(BuildTarget target, string path)
120147
{
121-
PostProcessResourceStripper stripper = new PostProcessResourceStripper();
122-
stripper.Apply(EditorUserBuildSettings.activeBuildTarget);
148+
PostProcessResourceStripper.Update(target);
123149
}
150+
#endif
124151
}
152+
#endif
153+
125154
}

0 commit comments

Comments
 (0)