-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWorldGenerator.cs
44 lines (35 loc) · 1.19 KB
/
WorldGenerator.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class WorldGenerator : MonoBehaviour
{
public int WorldSizeInChunks = 10;
public GameObject loadingScreen;
Dictionary<Vector3Int, Chunk> chunks = new Dictionary<Vector3Int, Chunk>();
void Start()
{
Generate();
}
void Generate()
{
loadingScreen.SetActive(true);
for (int x = 0; x < WorldSizeInChunks; x++)
{
for (int z = 0; z < WorldSizeInChunks; z++)
{
Vector3Int chunkPos = new Vector3Int(x * GameData.ChunkWidth, 0, z * GameData.ChunkWidth);
chunks.Add(chunkPos, new Chunk(chunkPos));
chunks[chunkPos].chunkObject.transform.SetParent(World.Instance.transform);
}
}
loadingScreen.SetActive(false);
Debug.Log(string.Format("{0} x {0} world generated.", (WorldSizeInChunks * GameData.ChunkWidth)));
}
public Chunk GetCHunkFromVector3(Vector3 pos)
{
int x = (int)pos.x;
int y = (int)pos.y;
int z = (int)pos.z;
return chunks[new Vector3Int(x, y, z)];
}
}