cell - delete Hex - refactor, feature State: stable В Hex перенесен функционал из cell.
70 lines
1.7 KiB
C#
70 lines
1.7 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
public class gridGen : MonoBehaviour
|
|
{
|
|
public perlinNoise noise;
|
|
public GameObject hexPrefab;
|
|
public Transform mapStart;
|
|
private float translationVert;
|
|
|
|
public int x = 32;
|
|
public int y = 32;
|
|
|
|
private float scaleY = Mathf.Sqrt(3) / 2;
|
|
private float scaleX = 1;
|
|
|
|
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));
|
|
*/
|
|
}
|
|
|
|
// Update is called once per frame
|
|
void Update()
|
|
{
|
|
if (nowX < x)
|
|
{
|
|
|
|
while (nowY < y)
|
|
{
|
|
float modX = 0.25f;
|
|
float modY = 0;
|
|
|
|
if (nowX % 2 == 1)
|
|
{
|
|
modY = 0.5f;
|
|
}
|
|
|
|
|
|
initHex(mapStart.position.x + (scaleX * nowX) - (modX*scaleX*nowX), mapStart.position.y + (scaleY * nowY) + (modY*scaleY));
|
|
nowY++;
|
|
}
|
|
|
|
{
|
|
nowX++;
|
|
nowY = 0;
|
|
}
|
|
}
|
|
}
|
|
|
|
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);
|
|
|
|
}
|
|
}
|