Fix scenes reload feature to check if can do it, properly use async in play mode and ask for save if scene is modified

#1740
This commit is contained in:
Wojtek Figat
2023-11-17 14:07:33 +01:00
parent b7f2196784
commit 15aaf5043a
2 changed files with 13 additions and 7 deletions

View File

@@ -242,7 +242,6 @@ namespace FlaxEditor.Modules
/// <param name="additive">True if don't close opened scenes and just add new scene to them, otherwise will release current scenes and load single one.</param>
public void OpenScene(Guid sceneId, bool additive = false)
{
// Check if cannot change scene now
if (!Editor.StateMachine.CurrentState.CanChangeScene)
return;
@@ -271,11 +270,21 @@ namespace FlaxEditor.Modules
/// </summary>
public void ReloadScenes()
{
if (!Editor.StateMachine.CurrentState.CanChangeScene)
return;
if (!Editor.IsPlayMode)
{
if (CheckSaveBeforeClose())
return;
}
// Reload scenes
foreach (var scene in Level.Scenes)
{
var sceneId = scene.ID;
if (!Level.UnloadScene(scene))
Level.LoadScene(sceneId);
Level.UnloadScene(scene);
Level.LoadScene(sceneId);
}
}
@@ -285,7 +294,6 @@ namespace FlaxEditor.Modules
/// <param name="scene">The scene.</param>
public void CloseScene(Scene scene)
{
// Check if cannot change scene now
if (!Editor.StateMachine.CurrentState.CanChangeScene)
return;
@@ -309,7 +317,6 @@ namespace FlaxEditor.Modules
/// </summary>
public void CloseAllScenes()
{
// Check if cannot change scene now
if (!Editor.StateMachine.CurrentState.CanChangeScene)
return;
@@ -334,7 +341,6 @@ namespace FlaxEditor.Modules
/// <param name="scene">The scene to not close.</param>
public void CloseAllScenesExcept(Scene scene)
{
// Check if cannot change scene now
if (!Editor.StateMachine.CurrentState.CanChangeScene)
return;

View File

@@ -1108,7 +1108,7 @@ bool LevelImpl::saveScene(Scene* scene)
bool LevelImpl::saveScene(Scene* scene, const String& path)
{
ASSERT(scene);
ASSERT(scene && EnumHasNoneFlags(scene->Flags, ObjectFlags::WasMarkedToDelete));
auto sceneId = scene->GetID();
LOG(Info, "Saving scene {0} to \'{1}\'", scene->GetName(), path);