private static void OnModeChangeLayouts(ModeChangedArgs args)
{
// Prevent double loading the default/last layout already done by the WindowLayout system.
if (args.prevIndex == -1)
{
return;
}
if (HasCapability(ModeCapability.LayoutSwitching, true))
{
WindowLayout.SaveCurrentLayoutPerMode(GetModeId(args.prevIndex));
try
{
if (args.nextIndex != 0 || args.prevIndex == -1 || HasCapability(args.prevIndex, ModeCapability.LayoutSwitching, true))
{
// Load the last valid layout for this mode
WindowLayout.LoadCurrentModeLayout(keepMainWindow: true);
}
}
catch (Exception)
{
// Error while loading layout. Load the default layout for current mode.
WindowLayout.LoadDefaultLayout();
}
}
if (HasCapability(ModeCapability.LayoutWindowMenu, true))
{
WindowLayout.ReloadWindowLayoutMenu();
EditorUtility.Internal_UpdateAllMenus();
}
}