From 6075ff72d60de79db1b50d7ba280486d779a1fae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mi=C5=82osz=20Matkowski?= Date: Fri, 23 Aug 2024 14:27:14 +0200 Subject: [PATCH] Fix duplicated Validation operations during Toolbox initialization --- .../Editor/ToolboxEditorSettings.cs | 16 ++++++++++++++-- Assets/Editor Toolbox/Editor/ToolboxManager.cs | 4 +++- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/Assets/Editor Toolbox/Editor/ToolboxEditorSettings.cs b/Assets/Editor Toolbox/Editor/ToolboxEditorSettings.cs index 401d58cb..8ed7b1ab 100644 --- a/Assets/Editor Toolbox/Editor/ToolboxEditorSettings.cs +++ b/Assets/Editor Toolbox/Editor/ToolboxEditorSettings.cs @@ -117,6 +117,7 @@ internal class ToolboxEditorSettings : ScriptableObject, IToolboxGeneralSettings private bool projectSettingsDirty; private bool inspectorSettingsDirty; private bool sceneViewSettingsDirty; + private int lastValidationFrame; internal event Action OnHierarchySettingsChanged; internal event Action OnProjectSettingsChanged; @@ -179,13 +180,25 @@ internal void ValidateSceneViewSettings() internal void Validate() { + Validate(false); + } + + internal void Validate(bool force) + { + //NOTE: additional check to prevent multiple validations in the same frame, e.g. typical case: + // - after recompilation we are initializing toolbox and we want to validate settings, in the same time Unity validates all SOs + if (lastValidationFrame == Time.frameCount && !force) + { + return; + } + ValidateHierarchySettings(); ValidateProjectSettings(); ValidateInspectorSettings(); ValidateSceneViewSettings(); + lastValidationFrame = Time.frameCount; } - /// /// Called internally by the Editor after any value change or the Undo/Redo operation. /// @@ -334,7 +347,6 @@ public void ResetIconRectProperties() Defaults.smallFolderIconYPaddingDefault); } - public bool UseToolboxHierarchy { get => useToolboxHierarchy; diff --git a/Assets/Editor Toolbox/Editor/ToolboxManager.cs b/Assets/Editor Toolbox/Editor/ToolboxManager.cs index 6447ec09..36ec4407 100644 --- a/Assets/Editor Toolbox/Editor/ToolboxManager.cs +++ b/Assets/Editor Toolbox/Editor/ToolboxManager.cs @@ -152,13 +152,15 @@ internal static bool TryInitializeSettings(string settingsGuid) //try to get proper settings asset from the provided guid if (Settings = AssetDatabase.LoadAssetAtPath(SettingsPath)) { + //TODO: instead of relying on validation events let's prepare appropriate initialize/deinitialize process for all sub-systems + //subscribe to all related events Settings.OnHierarchySettingsChanged += ManageHierarchyCore; Settings.OnProjectSettingsChanged += ManageProjectCore; Settings.OnInspectorSettingsChanged += ManageInspectorCore; Settings.OnSceneViewSettingsChanged += ManageSceneViewCore; //initialize core functionalities - Settings.Validate(); + Settings.Validate(true); return true; } else