diff --git a/Assets/scripts/gridGen.cs b/Assets/scripts/gridGen.cs index edd4d04..1492667 100644 --- a/Assets/scripts/gridGen.cs +++ b/Assets/scripts/gridGen.cs @@ -7,63 +7,71 @@ public class gridGen : MonoBehaviour public perlinNoise noise; public GameObject hexPrefab; public Transform mapStart; - private float translationVert; - public int x = 32; - public int y = 32; + public int generationStep = 128; //Количество генерируемых за кадр гексов + public int progressNow = 0; //Сколько уже сгенерированно + public int progressTotal = -1; //Всего гексов нужно сгенерировать + //private float translationVert; - private float scaleY = Mathf.Sqrt(3) / 2; - private float scaleX = 1; + public int x = 32;//Размер сетки по x + public int y = 32;//Размер сетки по y + + private float scaleY = Mathf.Sqrt(3) / 2; //Расчитываем корректный размер гекса по Oy для точных сдвигов + private float scaleX = 1; //Расчитываем корректный размер гекса по Ox для точных сдвигов + + private int nowX; //Координата текущего гекса по Ox + private int nowY; //Координата текущего гекса по Oy + private int nowStep = 0;//Сгенерированно за этот кадр - private int nowX; - private int nowY; - // Start is called before the first frame update void Start() { - /* - GameObject hex2 = Instantiate(hexPrefab); - hex2.transform.Translate(new Vector3(0, scaleY, 0)); - - GameObject hex3 = Instantiate(hexPrefab); - hex3.transform.Translate(new Vector3(0.75f*scaleX, 0.5f*scaleY, 0)); - */ + progressTotal = x * y;//Считаем сколько всего гексов в сетке } // Update is called once per frame void Update() { - if (nowX < x) + while (nowStep < generationStep && nowX < x) //Делаем generationStep за кадр и проверяем что генерация еще нужна { - - while (nowY < y) + + if (nowY < y)//Проверяем что столбец еще не закончен { - float modX = 0.25f; - float modY = 0; - + float modX = 0.25f; //Множитель для сдвига по Ox + float modY = 0; //Базовый множитель сдвига по Oy + if (nowX % 2 == 1) { - modY = 0.5f; + modY = 0.5f; //Сдвиг каждого нечетного столбца } - initHex(mapStart.position.x + (scaleX * nowX) - (modX*scaleX*nowX), mapStart.position.y + (scaleY * nowY) + (modY*scaleY)); - nowY++; + initHex(mapStart.position.x + (scaleX * nowX) - (modX * scaleX * nowX), mapStart.position.y + (scaleY * nowY) + (modY * scaleY));//Создание гекса со сдвигами + nowY++; //Увеличиваем номер сгенерированного гекса в столбце + progressNow++;//Увеличиваем счетчик прогресса + nowStep++;//Увеличиваем счетчик количества сгенерированных за кадр гексов } - + else //Если столбец заончился переходим к следующему { nowX++; nowY = 0; } + + + } + if (nowStep == generationStep) nowStep = 0;//Сбрасываем счетчик сгенерированных за кадр гексов + + if (nowX == x) this.enabled = false;//Завершаем генерацию после ее конца + } private void initHex(float x, float y) { - GameObject hex = Instantiate(hexPrefab); - hex.transform.Translate(new Vector3(x, y, 0)); - - hex.GetComponent().InitializeHex(new Vector2Int(this.nowX, this.nowY), noise.getNoise((float)nowX / this.x, (float)nowY / this.x, Mathf.Max(this.x, this.y)), noise.seed); - + GameObject hex = Instantiate(hexPrefab);//Создаем клон базового гекса + hex.transform.Translate(new Vector3(x, y, 0));//Сдвигаем клон на нужную позицию в сетке + + hex.GetComponent().InitializeHex(new Vector2Int(this.nowX, this.nowY), noise.getNoise((float)nowX / this.x, (float)nowY / this.x, Mathf.Max(this.x, this.y)), noise.seed);//Инициализируем логику гекса + } } diff --git a/Assets/scripts/miniMap.meta b/Assets/scripts/miniMap.meta new file mode 100644 index 0000000..6035aee --- /dev/null +++ b/Assets/scripts/miniMap.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 1aec07be2f1cdd5438c819666796f8bf +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/scripts/miniMap/MiniMapGenerator.cs b/Assets/scripts/miniMap/MiniMapGenerator.cs new file mode 100644 index 0000000..6f485d6 --- /dev/null +++ b/Assets/scripts/miniMap/MiniMapGenerator.cs @@ -0,0 +1,18 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class MiniMapGenerator : MonoBehaviour +{ + // Start is called before the first frame update + void Start() + { + + } + + // Update is called once per frame + void Update() + { + + } +} diff --git a/Assets/scripts/miniMap/MiniMapGenerator.cs.meta b/Assets/scripts/miniMap/MiniMapGenerator.cs.meta new file mode 100644 index 0000000..fff8729 --- /dev/null +++ b/Assets/scripts/miniMap/MiniMapGenerator.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 966127aa560664d43bdb73e9824ae9f9 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/scripts/miniMap/Tile.cs b/Assets/scripts/miniMap/Tile.cs new file mode 100644 index 0000000..874a143 --- /dev/null +++ b/Assets/scripts/miniMap/Tile.cs @@ -0,0 +1,18 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class Tile : MonoBehaviour +{ + // Start is called before the first frame update + void Start() + { + + } + + // Update is called once per frame + void Update() + { + + } +} diff --git a/Assets/scripts/miniMap/Tile.cs.meta b/Assets/scripts/miniMap/Tile.cs.meta new file mode 100644 index 0000000..fa3300b --- /dev/null +++ b/Assets/scripts/miniMap/Tile.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 452e22fcead7325429450f21972ae4b9 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: