reload map when map was modified

This commit is contained in:
2022-06-12 19:51:32 +03:00
parent 4b25d17b17
commit 3b6b5686d0
2 changed files with 32 additions and 5 deletions

View File

@@ -0,0 +1,12 @@
using System;
using FlaxEngine;
using FlaxEditor;
namespace Game
{
[ExecuteInEditMode]
public class LevelScript : Script
{
public DateTime MapTimestamp;
}
}

View File

@@ -335,11 +335,18 @@ namespace Game
worldSpawnActor = Actor.FindActor("WorldSpawn");
if (worldSpawnActor != null)
{
if (forceLoad)
#if FLAX_EDITOR
LevelScript levelScript = worldSpawnActor.GetScript<LevelScript>();
DateTime timestamp = File.GetLastWriteTime(mapPath);
if (timestamp != levelScript.MapTimestamp)
{
FlaxEngine.Debug.Log("Destroying children");
worldSpawnActor.DestroyChildren();
FlaxEngine.Debug.Log($"Map dirty, reloading. {timestamp.ToString()} != {levelScript.MapTimestamp.ToString()}");
forceLoad = true;
levelScript.MapTimestamp = timestamp;
}
#endif
if (forceLoad)
worldSpawnActor.DestroyChildren();
else
{
FlaxEngine.Debug.Log("Map already loaded in the scene");
@@ -348,7 +355,9 @@ namespace Game
}
}
else
FlaxEngine.Debug.Log("Loading map");
FlaxEngine.Debug.Log("No WorldSpawn, loading map");
FlaxEngine.Debug.Log("Loading map");
{
string matBasePath = Path.Combine(AssetManager.ContentPath, "Materials");
@@ -372,7 +381,13 @@ namespace Game
{
worldSpawnActor = Actor.AddChild<Actor>();
worldSpawnActor.Name = "WorldSpawn";
worldSpawnActor.HideFlags |= HideFlags.DontSave;
LevelScript levelScript = worldSpawnActor.AddScript<LevelScript>();
#if FLAX_EDITOR
levelScript.MapTimestamp = File.GetLastWriteTime(mapPath);
#endif
worldSpawnActor.HideFlags &= ~HideFlags.DontSave;
//worldSpawnActor.HideFlags |= HideFlags.DontSave;
//worldSpawnActor.HideFlags |= HideFlags.DontSelect;
}