refactor: gridGen

- configurable hex per frame count
 - restructure
 - comments
 - progress counters
This commit is contained in:
2026-01-16 23:31:25 +03:00
parent e4e834d373
commit e3f865116f
6 changed files with 104 additions and 30 deletions

View File

@@ -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<Hex>().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<Hex>().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);//Èíèöèàëèçèðóåì ëîãèêó ãåêñà
}
}

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 1aec07be2f1cdd5438c819666796f8bf
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -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()
{
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 966127aa560664d43bdb73e9824ae9f9
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -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()
{
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 452e22fcead7325429450f21972ae4b9
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: