refactor: gridGen
- configurable hex per frame count - restructure - comments - progress counters
This commit is contained in:
@@ -7,63 +7,71 @@ public class gridGen : MonoBehaviour
|
|||||||
public perlinNoise noise;
|
public perlinNoise noise;
|
||||||
public GameObject hexPrefab;
|
public GameObject hexPrefab;
|
||||||
public Transform mapStart;
|
public Transform mapStart;
|
||||||
private float translationVert;
|
|
||||||
|
|
||||||
public int x = 32;
|
public int generationStep = 128; //Êîëè÷åñòâî ãåíåðèðóåìûõ çà êàäð ãåêñîâ
|
||||||
public int y = 32;
|
public int progressNow = 0; //Ñêîëüêî óæå ñãåíåðèðîâàííî
|
||||||
|
public int progressTotal = -1; //Âñåãî ãåêñîâ íóæíî ñãåíåðèðîâàòü
|
||||||
|
//private float translationVert;
|
||||||
|
|
||||||
private float scaleY = Mathf.Sqrt(3) / 2;
|
public int x = 32;//Ðàçìåð ñåòêè ïî x
|
||||||
private float scaleX = 1;
|
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
|
// Start is called before the first frame update
|
||||||
void Start()
|
void Start()
|
||||||
{
|
{
|
||||||
/*
|
progressTotal = x * y;//Ñ÷èòàåì ñêîëüêî âñåãî ãåêñîâ â ñåòêå
|
||||||
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));
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update is called once per frame
|
// Update is called once per frame
|
||||||
void Update()
|
void Update()
|
||||||
{
|
{
|
||||||
if (nowX < x)
|
while (nowStep < generationStep && nowX < x) //Äåëàåì generationStep çà êàäð è ïðîâåðÿåì ÷òî ãåíåðàöèÿ åùå íóæíà
|
||||||
{
|
{
|
||||||
|
|
||||||
while (nowY < y)
|
if (nowY < y)//Ïðîâåðÿåì ÷òî ñòîëáåö åùå íå çàêîí÷åí
|
||||||
{
|
{
|
||||||
float modX = 0.25f;
|
float modX = 0.25f; //Ìíîæèòåëü äëÿ ñäâèãà ïî Ox
|
||||||
float modY = 0;
|
float modY = 0; //Áàçîâûé ìíîæèòåëü ñäâèãà ïî Oy
|
||||||
|
|
||||||
if (nowX % 2 == 1)
|
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));
|
initHex(mapStart.position.x + (scaleX * nowX) - (modX * scaleX * nowX), mapStart.position.y + (scaleY * nowY) + (modY * scaleY));//Ñîçäàíèå ãåêñà ñî ñäâèãàìè
|
||||||
nowY++;
|
nowY++; //Óâåëè÷èâàåì íîìåð ñãåíåðèðîâàííîãî ãåêñà â ñòîëáöå
|
||||||
|
progressNow++;//Óâåëè÷èâàåì ñ÷åò÷èê ïðîãðåññà
|
||||||
|
nowStep++;//Óâåëè÷èâàåì ñ÷åò÷èê êîëè÷åñòâà ñãåíåðèðîâàííûõ çà êàäð ãåêñîâ
|
||||||
}
|
}
|
||||||
|
else //Åñëè ñòîëáåö çàîí÷èëñÿ ïåðåõîäèì ê ñëåäóþùåìó
|
||||||
{
|
{
|
||||||
nowX++;
|
nowX++;
|
||||||
nowY = 0;
|
nowY = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
if (nowStep == generationStep) nowStep = 0;//Ñáðàñûâàåì ñ÷åò÷èê ñãåíåðèðîâàííûõ çà êàäð ãåêñîâ
|
||||||
|
|
||||||
|
if (nowX == x) this.enabled = false;//Çàâåðøàåì ãåíåðàöèþ ïîñëå åå êîíöà
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initHex(float x, float y)
|
private void initHex(float x, float y)
|
||||||
{
|
{
|
||||||
GameObject hex = Instantiate(hexPrefab);
|
GameObject hex = Instantiate(hexPrefab);//Ñîçäàåì êëîí áàçîâîãî ãåêñà
|
||||||
hex.transform.Translate(new Vector3(x, y, 0));
|
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);
|
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);//Èíèöèàëèçèðóåì ëîãèêó ãåêñà
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
8
Assets/scripts/miniMap.meta
Normal file
8
Assets/scripts/miniMap.meta
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 1aec07be2f1cdd5438c819666796f8bf
|
||||||
|
folderAsset: yes
|
||||||
|
DefaultImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
18
Assets/scripts/miniMap/MiniMapGenerator.cs
Normal file
18
Assets/scripts/miniMap/MiniMapGenerator.cs
Normal 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()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
11
Assets/scripts/miniMap/MiniMapGenerator.cs.meta
Normal file
11
Assets/scripts/miniMap/MiniMapGenerator.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 966127aa560664d43bdb73e9824ae9f9
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
18
Assets/scripts/miniMap/Tile.cs
Normal file
18
Assets/scripts/miniMap/Tile.cs
Normal 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()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
11
Assets/scripts/miniMap/Tile.cs.meta
Normal file
11
Assets/scripts/miniMap/Tile.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 452e22fcead7325429450f21972ae4b9
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
Reference in New Issue
Block a user