|
@@ -291,6 +291,9 @@ namespace bs.Editor
|
|
|
private static bool unitTestsExecuted;
|
|
private static bool unitTestsExecuted;
|
|
|
private static EditorPersistentData persistentData;
|
|
private static EditorPersistentData persistentData;
|
|
|
|
|
|
|
|
|
|
+ private static bool delayUnloadProject;
|
|
|
|
|
+ private static Action delayUnloadCallback;
|
|
|
|
|
+
|
|
|
#pragma warning disable 0414
|
|
#pragma warning disable 0414
|
|
|
private static EditorApplication instance;
|
|
private static EditorApplication instance;
|
|
|
#pragma warning restore 0414
|
|
#pragma warning restore 0414
|
|
@@ -373,6 +376,15 @@ namespace bs.Editor
|
|
|
// Update managers
|
|
// Update managers
|
|
|
ProjectLibrary.Update();
|
|
ProjectLibrary.Update();
|
|
|
codeManager.Update();
|
|
codeManager.Update();
|
|
|
|
|
+
|
|
|
|
|
+ if (delayUnloadProject)
|
|
|
|
|
+ {
|
|
|
|
|
+ delayUnloadProject = false;
|
|
|
|
|
+ UnloadProject();
|
|
|
|
|
+
|
|
|
|
|
+ delayUnloadCallback?.Invoke();
|
|
|
|
|
+ delayUnloadCallback = null;
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
/// <summary>
|
|
@@ -730,9 +742,9 @@ namespace bs.Editor
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
if (IsProjectLoaded)
|
|
if (IsProjectLoaded)
|
|
|
- UnloadProject();
|
|
|
|
|
-
|
|
|
|
|
- Internal_LoadProject(path); // Triggers Internal_OnProjectLoaded when done
|
|
|
|
|
|
|
+ TryUnloadProject(() => Internal_LoadProject(path));
|
|
|
|
|
+ else
|
|
|
|
|
+ Internal_LoadProject(path); // Triggers Internal_OnProjectLoaded when done
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
/// <summary>
|
|
@@ -828,47 +840,83 @@ namespace bs.Editor
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
/// <summary>
|
|
|
- /// Unloads the currently loaded project. Offers the user a chance to save the current scene if it is modified.
|
|
|
|
|
- /// Automatically saves all project data before unloading.
|
|
|
|
|
|
|
+ /// Attempts to unload the currently loaded project. Offers the user a chance to save the current scene if it is
|
|
|
|
|
+ /// modified. Automatically saves all project data before unloading.
|
|
|
/// </summary>
|
|
/// </summary>
|
|
|
- private static void UnloadProject()
|
|
|
|
|
|
|
+ /// <param name="onDone">Callback to trigger when project project unload is done.</param>
|
|
|
|
|
+ private static void TryUnloadProject(Action onDone)
|
|
|
{
|
|
{
|
|
|
- Action continueUnload =
|
|
|
|
|
- () =>
|
|
|
|
|
- {
|
|
|
|
|
- Scene.Clear();
|
|
|
|
|
|
|
+ if (delayUnloadProject)
|
|
|
|
|
+ return;
|
|
|
|
|
|
|
|
- if (monitor != null)
|
|
|
|
|
|
|
+ AskToSaveSceneAndContinue(
|
|
|
|
|
+ () =>
|
|
|
|
|
+ {
|
|
|
|
|
+ if (ProjectLibrary.ImportInProgress)
|
|
|
{
|
|
{
|
|
|
- monitor.Destroy();
|
|
|
|
|
- monitor = null;
|
|
|
|
|
|
|
+ ConfirmImportInProgressWindow.Show();
|
|
|
|
|
+ delayUnloadCallback = onDone;
|
|
|
|
|
+ delayUnloadProject = true;
|
|
|
}
|
|
}
|
|
|
|
|
+ else
|
|
|
|
|
+ {
|
|
|
|
|
+ UnloadProject();
|
|
|
|
|
+ onDone?.Invoke();
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- LibraryWindow window = EditorWindow.GetWindow<LibraryWindow>();
|
|
|
|
|
- if(window != null)
|
|
|
|
|
- window.Reset();
|
|
|
|
|
-
|
|
|
|
|
- SetSceneDirty(false);
|
|
|
|
|
- Internal_UnloadProject();
|
|
|
|
|
- SetStatusProject(false);
|
|
|
|
|
- };
|
|
|
|
|
|
|
+ /// <summary>
|
|
|
|
|
+ /// Unloads the currently loaded project, without making any checks or requiring confirmation.
|
|
|
|
|
+ /// </summary>
|
|
|
|
|
+ private static void UnloadProject()
|
|
|
|
|
+ {
|
|
|
|
|
+ Scene.Clear();
|
|
|
|
|
|
|
|
- Action<DialogBox.ResultType> dialogCallback =
|
|
|
|
|
- (result) =>
|
|
|
|
|
|
|
+ if (monitor != null)
|
|
|
{
|
|
{
|
|
|
- if (result == DialogBox.ResultType.Yes)
|
|
|
|
|
- SaveScene();
|
|
|
|
|
|
|
+ monitor.Destroy();
|
|
|
|
|
+ monitor = null;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ LibraryWindow window = EditorWindow.GetWindow<LibraryWindow>();
|
|
|
|
|
+ if (window != null)
|
|
|
|
|
+ window.Reset();
|
|
|
|
|
+
|
|
|
|
|
+ SetSceneDirty(false);
|
|
|
|
|
+ Internal_UnloadProject();
|
|
|
|
|
+ SetStatusProject(false);
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- continueUnload();
|
|
|
|
|
|
|
+ /// <summary>
|
|
|
|
|
+ /// Checks if the current scene is modified and asks the user to save the scene if it is. Triggers the
|
|
|
|
|
+ /// <see cref="next"/> callback when done, unless user cancels the operation.
|
|
|
|
|
+ /// </summary>
|
|
|
|
|
+ /// <param name="next">Callback to trigger after this method finishes.</param>
|
|
|
|
|
+ internal static void AskToSaveSceneAndContinue(Action next)
|
|
|
|
|
+ {
|
|
|
|
|
+ Action trySaveScene = null;
|
|
|
|
|
+ trySaveScene = () =>
|
|
|
|
|
+ {
|
|
|
|
|
+ SaveScene(next, trySaveScene);
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
|
|
+ Action<DialogBox.ResultType> dialogCallback =
|
|
|
|
|
+ (result) =>
|
|
|
|
|
+ {
|
|
|
|
|
+ if (result == DialogBox.ResultType.Yes)
|
|
|
|
|
+ trySaveScene();
|
|
|
|
|
+ else if (result == DialogBox.ResultType.No)
|
|
|
|
|
+ next?.Invoke();
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
if (IsSceneModified())
|
|
if (IsSceneModified())
|
|
|
{
|
|
{
|
|
|
DialogBox.Open("Warning", "You current scene has modifications. Do you wish to save them first?",
|
|
DialogBox.Open("Warning", "You current scene has modifications. Do you wish to save them first?",
|
|
|
DialogBox.Type.YesNoCancel, dialogCallback);
|
|
DialogBox.Type.YesNoCancel, dialogCallback);
|
|
|
}
|
|
}
|
|
|
else
|
|
else
|
|
|
- continueUnload();
|
|
|
|
|
|
|
+ next?.Invoke();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
/// <summary>
|