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