|
@@ -1,6 +1,7 @@
|
|
|
using System.Collections;
|
|
|
using System.Collections.Generic;
|
|
|
using UnityEngine;
|
|
|
+using NavMeshSurface = UnityEngine.AI.NavMeshSurface;
|
|
|
using KairoEngine.Core;
|
|
|
using KairoEngine.Chunks;
|
|
|
using KairoEngine.NoiseUtilities;
|
|
@@ -8,6 +9,7 @@ using Utilities = KairoEngine.Utility.Utilities;
|
|
|
using Sirenix.OdinInspector;
|
|
|
using UniRx;
|
|
|
|
|
|
+
|
|
|
namespace KairoEngine.TerrainEngine
|
|
|
{
|
|
|
[HideMonoScript]
|
|
@@ -20,6 +22,8 @@ namespace KairoEngine.TerrainEngine
|
|
|
[BoxGroup("Configurations"), ShowIf("@startConfiguration == StartConfig.WaitForEvent")] public string generateWorldEvent = "GenerateWorld";
|
|
|
[BoxGroup("Configurations")] public int dataProcessLimit = 4;
|
|
|
[BoxGroup("Configurations")] public int parallelMeshJobs = 4;
|
|
|
+ [HorizontalGroup("Configurations/NavMesh")] public bool processNavMesh = false;
|
|
|
+ [HorizontalGroup("Configurations/NavMesh"), ShowIf("@processNavMesh"), HideLabel] public NavMeshSurface navMeshSurface;
|
|
|
[BoxGroup("Configurations")] public bool showChunkData = false;
|
|
|
|
|
|
[InlineProperty, HideLabel, BoxGroup("Marching Cubes")] public MarchingCubes4 marchingCubes = new();
|
|
@@ -248,6 +252,7 @@ namespace KairoEngine.TerrainEngine
|
|
|
|
|
|
private void ProcessChunkMeshBuffer()
|
|
|
{
|
|
|
+ bool terrainChanged = false;
|
|
|
marchingCubes.UpdateFinishedJobs();
|
|
|
int limit = marchingCubes.GetJobCount() < parallelMeshJobs ? parallelMeshJobs - marchingCubes.GetJobCount() : 0;
|
|
|
limit = limit < chunkMeshBuffer.Count ? limit : chunkMeshBuffer.Count;
|
|
@@ -255,7 +260,11 @@ namespace KairoEngine.TerrainEngine
|
|
|
{
|
|
|
GenerateTerrainMesh(chunkMeshBuffer[i]);
|
|
|
}
|
|
|
+ if(chunkMeshBuffer.Count > 0) terrainChanged = true;
|
|
|
chunkMeshBuffer.RemoveRange(0, limit);
|
|
|
+ if(!processNavMesh) return;
|
|
|
+ if(terrainChanged && chunkMeshBuffer.Count == 0 && chunkDataBuffer.Count == 0 && navMeshSurface != null)
|
|
|
+ Timer.ExecuteRealTime(50, () => navMeshSurface.BuildNavMesh());
|
|
|
}
|
|
|
|
|
|
public void DestroyChunk(Vector3 position)
|