Skip to content

Commit 3a386d1

Browse files
committed
fix: settings recreation on access from the package settings window.
1 parent 94cf9f1 commit 3a386d1

File tree

1 file changed

+23
-16
lines changed

1 file changed

+23
-16
lines changed

com.stansassets.plugins-dev-kit/Editor/UIToolkit/SettingsWindow/PackageSettingsWindow.cs

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -24,32 +24,39 @@ public abstract class PackageSettingsWindow<TWindow> : EditorWindow where TWindo
2424
protected readonly Dictionary<string, VisualElement> m_Tabs = new Dictionary<string, VisualElement>();
2525

2626
readonly string m_WindowUIFilesRootPath = $"{PluginsDevKitPackage.UIToolkitPath}/SettingsWindow";
27-
27+
2828
void OnEnable()
2929
{
30-
var root = rootVisualElement;
31-
UIToolkitEditorUtility.CloneTreeAndApplyStyle(root, $"{m_WindowUIFilesRootPath}/PackageSettingsWindow");
30+
// This is a workaround due to a very weird bug.
31+
// During OnEnable we may need to accesses singleton scriptable object associated with the package.
32+
// And looks like AssetDatabase could be not ready and we will recreate new empty settings objects
33+
// instead of getting existing one.
34+
EditorApplication.delayCall += () =>
35+
{
36+
var root = rootVisualElement;
37+
UIToolkitEditorUtility.CloneTreeAndApplyStyle(root, $"{m_WindowUIFilesRootPath}/PackageSettingsWindow");
3238

33-
m_TabsContainer = root.Q<ScrollView>("tabs-container");
39+
m_TabsContainer = root.Q<ScrollView>("tabs-container");
3440

35-
var packageInfo = GetPackageInfo();
36-
root.Q<Label>("display-name").text = packageInfo.displayName.Remove(0, "Stans Assets - ".Length);
37-
root.Q<Label>("description").text = packageInfo.description;
38-
root.Q<Label>("version").text = $"Version: {packageInfo.version}";
41+
var packageInfo = GetPackageInfo();
42+
root.Q<Label>("display-name").text = packageInfo.displayName.Remove(0, "Stans Assets - ".Length);
43+
root.Q<Label>("description").text = packageInfo.description;
44+
root.Q<Label>("version").text = $"Version: {packageInfo.version}";
3945

40-
m_TabsButtons = root.Q<ButtonStrip>();
41-
m_TabsButtons.CleanUp();
42-
m_TabsButtons.OnButtonClick += ActivateTab;
46+
m_TabsButtons = root.Q<ButtonStrip>();
47+
m_TabsButtons.CleanUp();
48+
m_TabsButtons.OnButtonClick += ActivateTab;
4349

44-
OnWindowEnable(root);
45-
ActivateTab();
50+
OnWindowEnable(root);
51+
ActivateTab();
52+
};
4653
}
4754

4855
void ActivateTab()
4956
{
50-
if(string.IsNullOrEmpty(m_TabsButtons.Value))
57+
if (string.IsNullOrEmpty(m_TabsButtons.Value))
5158
return;
52-
59+
5360
foreach (var tab in m_Tabs)
5461
tab.Value.RemoveFromHierarchy();
5562

@@ -98,4 +105,4 @@ public static TWindow ShowTowardsInspector(string windowTitle, Texture icon)
98105
}
99106
}
100107
}
101-
#endif
108+
#endif

0 commit comments

Comments
 (0)