From eab47305629d96d19626e10b649ba4247d1f55f5 Mon Sep 17 00:00:00 2001
From: miepzerino <o.skotnik@gmail.com>
Date: Sat, 23 Dec 2023 21:20:31 +0000
Subject: [PATCH] Added loading screen, moved tilemap generation to coroutine

---
 Assets/GenerateTileMap.cs |   27 +++++++++++++--------------
 1 files changed, 13 insertions(+), 14 deletions(-)

diff --git a/Assets/GenerateTileMap.cs b/Assets/GenerateTileMap.cs
index 4239562..2d3e10f 100644
--- a/Assets/GenerateTileMap.cs
+++ b/Assets/GenerateTileMap.cs
@@ -1,5 +1,5 @@
+using System;
 using System.Collections;
-using System.Collections.Generic;
 using UnityEngine;
 using UnityEngine.Tilemaps;
 
@@ -13,19 +13,17 @@
     Tilemap tilemap;
     public RuleTile ruleTile;
     //public List<TileBase> tiles;
-    // Start is called before the first frame update
-    void Start()
+
+    private void Awake()
     {
         tilemap = GetComponent<Tilemap>();
-        GenerateTiles();
     }
 
-
-    public void GenerateTiles()
+    public IEnumerator GenerateTiles(Action finishedCallback)
     {
         for (int x = 0; x < width; x++)
         {
-            for(int y = 0; y < height; y++)
+            for (int y = 0; y < height; y++)
             {
                 float xPerlin = ((float)x / width) * scale + offsetX;
                 float yPerlin = ((float)y / height) * scale + offsetY;
@@ -33,16 +31,17 @@
 
                 if (perlinNoise >= 0.3f)
                 {
-                    if (!tilemap.HasTile(new Vector3Int(x,y+1))) {
-                        tilemap.SetTile(new Vector3Int(x, y), ruleTile);
-                    } 
-                    else
-                    {
-                        tilemap.SetTile(new Vector3Int(x, y), ruleTile);
-                    }
+                    tilemap.SetTile(new Vector3Int(x, y), ruleTile);
                 }
 
             }
+
+            // Update UI every 8 lines
+            if ((x % 8) == 0)
+            {
+                yield return null;
+            }
         }
+        finishedCallback();
     }
 }

--
Gitblit v1.9.3