Skip to content

Commit

Permalink
Fix duplicated Validation operations during Toolbox initialization
Browse files Browse the repository at this point in the history
  • Loading branch information
arimger committed Aug 23, 2024
1 parent a53a884 commit 6075ff7
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
16 changes: 14 additions & 2 deletions Assets/Editor Toolbox/Editor/ToolboxEditorSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ internal class ToolboxEditorSettings : ScriptableObject, IToolboxGeneralSettings
private bool projectSettingsDirty;
private bool inspectorSettingsDirty;
private bool sceneViewSettingsDirty;
private int lastValidationFrame;

internal event Action<IToolboxHierarchySettings> OnHierarchySettingsChanged;
internal event Action<IToolboxProjectSettings> OnProjectSettingsChanged;
Expand Down Expand Up @@ -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;
}


/// <summary>
/// Called internally by the Editor after any value change or the Undo/Redo operation.
/// </summary>
Expand Down Expand Up @@ -334,7 +347,6 @@ public void ResetIconRectProperties()
Defaults.smallFolderIconYPaddingDefault);
}


public bool UseToolboxHierarchy
{
get => useToolboxHierarchy;
Expand Down
4 changes: 3 additions & 1 deletion Assets/Editor Toolbox/Editor/ToolboxManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -152,13 +152,15 @@ internal static bool TryInitializeSettings(string settingsGuid)
//try to get proper settings asset from the provided guid
if (Settings = AssetDatabase.LoadAssetAtPath<ToolboxEditorSettings>(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
Expand Down

0 comments on commit 6075ff7

Please sign in to comment.