Browse Source

Added terrain generation on start or on Generic Event

James Peret 2 years ago
parent
commit
f6b61009c6
4 changed files with 37 additions and 2 deletions
  1. 7 0
      ChangeLog.md
  2. 7 0
      ChangeLog.md.meta
  3. 3 1
      Readme.md
  4. 20 1
      Runtime/ChunkTerrainGenerator.cs

+ 7 - 0
ChangeLog.md

@@ -0,0 +1,7 @@
+# Change Log
+
+### v0.0.2
+
+- Added terrain generation on start or on Generic Event
+- Added ability to change the generated terrain mesh GameObject tag
+- Added ability to change the generated terrain mesh GameObject layer

+ 7 - 0
ChangeLog.md.meta

@@ -0,0 +1,7 @@
+fileFormatVersion: 2
+guid: 231eac2ebfd85d9468f5ee8ba469fe59
+TextScriptImporter:
+  externalObjects: {}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 3 - 1
Readme.md

@@ -1 +1,3 @@
-# Terrain Engine v0.0.1
+# Terrain Engine v0.0.2
+
+[Change Log](ChangeLog.md)

+ 20 - 1
Runtime/ChunkTerrainGenerator.cs

@@ -13,10 +13,11 @@ namespace KairoEngine.TerrainEngine
     [HideMonoScript]
     public class ChunkTerrainGenerator : MonoBehaviour
     {
-        
         [BoxGroup("Configurations")] public Vector3 voxelSize = new Vector3(1f, 1f, 1f);
         [BoxGroup("Configurations")] public Vector3Int chunkSize = new Vector3Int(16, 16, 16);
         [BoxGroup("Configurations")] public Vector3Int chunkLimit = new Vector3Int(2, 1, 2);
+        [BoxGroup("Configurations")] public StartConfig startConfiguration = StartConfig.DoNothing;
+        [BoxGroup("Configurations"), ShowIf("@startConfiguration == StartConfig.WaitForEvent")] public string generateWorldEvent = "GenerateWorld";
         [BoxGroup("Configurations")] public int dataProcessLimit = 4;
         [BoxGroup("Configurations")] public int parallelMeshJobs = 4;
         [BoxGroup("Configurations")] public bool showChunkData = false;
@@ -46,11 +47,22 @@ namespace KairoEngine.TerrainEngine
         }
         private Dictionary<Vector3,List<VoxelUpdateData>> chunkUpdates = new Dictionary<Vector3, List<VoxelUpdateData>>();
 
+        private void Start()
+        {
+            if(startConfiguration == StartConfig.GenerateOnStart) GenerateWorld();
+            else if(startConfiguration == StartConfig.WaitForEvent) GenericEvents.StartListening(generateWorldEvent, GenerateWorld);
+        }
+
         private void Update()
         {
             marchingCubes.UpdateFinishedJobs();
         }
 
+        private void OnDisable()
+        {
+            if(startConfiguration == StartConfig.WaitForEvent) GenericEvents.StopListening(generateWorldEvent, GenerateWorld);
+        }
+
         private void OnDestroy()
         {
             marchingCubes.OnDestroy();
@@ -405,5 +417,12 @@ namespace KairoEngine.TerrainEngine
         {
 
         }
+
+        public enum StartConfig
+        {
+            DoNothing,
+            GenerateOnStart,
+            WaitForEvent
+        }
     }
 }