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

Commit 1c63912

Browse files
committed
Fixed domain reload issues
1 parent f7b9bf5 commit 1c63912

1 file changed

Lines changed: 58 additions & 34 deletions

File tree

PostProcessing/Editor/PostProcessLayerEditor.cs

Lines changed: 58 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -69,40 +69,6 @@ void OnEnable()
6969

7070
m_ShowToolkit = serializedObject.FindProperty("m_ShowToolkit");
7171
m_ShowCustomSorter = serializedObject.FindProperty("m_ShowCustomSorter");
72-
73-
// In case of domain reload, if the inspector is opened on a disabled PostProcessLayer
74-
// component it won't go through its OnEnable() and thus will miss bundle initialization
75-
// so force it there - also for some reason, an editor's OnEnable() can be called before
76-
// the component's so this will fix that as well.
77-
m_Target.InitBundles();
78-
79-
// Create a reorderable list for each injection event
80-
m_CustomLists = new Dictionary<PostProcessEvent, ReorderableList>();
81-
foreach (var evt in Enum.GetValues(typeof(PostProcessEvent)).Cast<PostProcessEvent>())
82-
{
83-
var bundles = m_Target.sortedBundles[evt];
84-
var listName = ObjectNames.NicifyVariableName(evt.ToString());
85-
86-
var list = new ReorderableList(bundles, typeof(SerializedBundleRef), true, true, false, false);
87-
88-
list.drawHeaderCallback = (rect) =>
89-
{
90-
EditorGUI.LabelField(rect, listName);
91-
};
92-
93-
list.drawElementCallback = (rect, index, isActive, isFocused) =>
94-
{
95-
var sbr = (SerializedBundleRef)list.list[index];
96-
EditorGUI.LabelField(rect, sbr.bundle.attribute.menuItem);
97-
};
98-
99-
list.onReorderCallback = (l) =>
100-
{
101-
EditorUtility.SetDirty(m_Target);
102-
};
103-
104-
m_CustomLists.Add(evt, list);
105-
}
10672
}
10773

10874
void OnDisable()
@@ -283,8 +249,66 @@ void DoCustomEffectSorter()
283249

284250
if (m_ShowCustomSorter.boolValue)
285251
{
252+
bool isInPrefab = false;
253+
254+
// Init lists if needed
255+
if (m_CustomLists == null)
256+
{
257+
// In some cases the editor will refresh before components which means
258+
// components might not have been fully initialized yet. In this case we also
259+
// need to make sure that we're not in a prefab as sorteBundles isn't a
260+
// serializable object and won't exist until put on a scene.
261+
if (m_Target.sortedBundles == null)
262+
{
263+
isInPrefab = string.IsNullOrEmpty(m_Target.gameObject.scene.name);
264+
265+
if (!isInPrefab)
266+
{
267+
// sortedBundles will be initialized and ready to use on the next frame
268+
Repaint();
269+
}
270+
}
271+
else
272+
{
273+
// Create a reorderable list for each injection event
274+
m_CustomLists = new Dictionary<PostProcessEvent, ReorderableList>();
275+
foreach (var evt in Enum.GetValues(typeof(PostProcessEvent)).Cast<PostProcessEvent>())
276+
{
277+
var bundles = m_Target.sortedBundles[evt];
278+
var listName = ObjectNames.NicifyVariableName(evt.ToString());
279+
280+
var list = new ReorderableList(bundles, typeof(SerializedBundleRef), true, true, false, false);
281+
282+
list.drawHeaderCallback = (rect) =>
283+
{
284+
EditorGUI.LabelField(rect, listName);
285+
};
286+
287+
list.drawElementCallback = (rect, index, isActive, isFocused) =>
288+
{
289+
var sbr = (SerializedBundleRef)list.list[index];
290+
EditorGUI.LabelField(rect, sbr.bundle.attribute.menuItem);
291+
};
292+
293+
list.onReorderCallback = (l) =>
294+
{
295+
EditorUtility.SetDirty(m_Target);
296+
};
297+
298+
m_CustomLists.Add(evt, list);
299+
}
300+
}
301+
}
302+
286303
GUILayout.Space(5);
287304

305+
if (isInPrefab)
306+
{
307+
EditorGUILayout.HelpBox("Not supported in prefabs.", MessageType.Info);
308+
GUILayout.Space(3);
309+
return;
310+
}
311+
288312
bool anyList = false;
289313
if (m_CustomLists != null)
290314
{

0 commit comments

Comments
 (0)