Add chunks

This commit is contained in:
Sofia 2020-04-20 03:37:56 +03:00
parent 45a1f05761
commit e68df78beb
6 changed files with 20 additions and 4 deletions

View File

@ -11,7 +11,7 @@ Material:
m_Shader: {fileID: 46, guid: 0000000000000000f000000000000000, type: 0} m_Shader: {fileID: 46, guid: 0000000000000000f000000000000000, type: 0}
m_ShaderKeywords: m_ShaderKeywords:
m_LightmapFlags: 4 m_LightmapFlags: 4
m_EnableInstancingVariants: 0 m_EnableInstancingVariants: 1
m_DoubleSidedGI: 0 m_DoubleSidedGI: 0
m_CustomRenderQueue: -1 m_CustomRenderQueue: -1
stringTagMap: {} stringTagMap: {}

View File

@ -11,7 +11,7 @@ Material:
m_Shader: {fileID: 46, guid: 0000000000000000f000000000000000, type: 0} m_Shader: {fileID: 46, guid: 0000000000000000f000000000000000, type: 0}
m_ShaderKeywords: m_ShaderKeywords:
m_LightmapFlags: 4 m_LightmapFlags: 4
m_EnableInstancingVariants: 0 m_EnableInstancingVariants: 1
m_DoubleSidedGI: 0 m_DoubleSidedGI: 0
m_CustomRenderQueue: -1 m_CustomRenderQueue: -1
stringTagMap: {} stringTagMap: {}

View File

@ -11,7 +11,7 @@ Material:
m_Shader: {fileID: 46, guid: 0000000000000000f000000000000000, type: 0} m_Shader: {fileID: 46, guid: 0000000000000000f000000000000000, type: 0}
m_ShaderKeywords: m_ShaderKeywords:
m_LightmapFlags: 4 m_LightmapFlags: 4
m_EnableInstancingVariants: 0 m_EnableInstancingVariants: 1
m_DoubleSidedGI: 0 m_DoubleSidedGI: 0
m_CustomRenderQueue: -1 m_CustomRenderQueue: -1
stringTagMap: {} stringTagMap: {}

View File

@ -26,6 +26,9 @@ public class Lorax : MonoBehaviour {
private int LastSeed = -1; private int LastSeed = -1;
private Vector3[][] TreePositions; private Vector3[][] TreePositions;
private int ChunkSize = 20;
private GameObject[] Chunks;
void Start() { void Start() {
} }
@ -48,10 +51,16 @@ public class Lorax : MonoBehaviour {
TotalChances[x + 1] = Counter + Chances[x]; TotalChances[x + 1] = Counter + Chances[x];
Counter = TotalChances[x + 1]; Counter = TotalChances[x + 1];
} }
Chunks = new GameObject[(500 / ChunkSize) * (500 / ChunkSize)];
TreePositions = new Vector3[cap][]; TreePositions = new Vector3[cap][];
for (int y = 0; y < cap; y++) { for (int y = 0; y < cap; y++) {
TreePositions[y] = new Vector3[cap]; TreePositions[y] = new Vector3[cap];
for (int x = 0; x < cap; x++) { for (int x = 0; x < cap; x++) {
int CurrentChunk = (int)((Mathf.Floor(y * Denseness / ChunkSize) * 20) + Mathf.Floor(x * Denseness / ChunkSize));
if (Chunks[CurrentChunk] == null) {
Chunks[CurrentChunk] = new GameObject("Chunk " + CurrentChunk);
Chunks[CurrentChunk].transform.parent = transform;
}
if (Random.value > TreeChance) { if (Random.value > TreeChance) {
continue; continue;
} }
@ -79,10 +88,17 @@ public class Lorax : MonoBehaviour {
} }
} }
var rot = Quaternion.Euler(0, 360 * Random.value, 0); var rot = Quaternion.Euler(0, 360 * Random.value, 0);
var obj = GameObject.Instantiate(Chosen, pos, rot, gameObject.transform); var obj = GameObject.Instantiate(Chosen, pos, rot, Chunks[CurrentChunk].transform);
} }
} }
} }
} }
} }
public GameObject GetChunkAt(float x, float y) {
y += 250;
x += 250;
int CurrentChunk = (int)((Mathf.Floor(y / ChunkSize) * 20) + Mathf.Floor(x / ChunkSize));
return Chunks[CurrentChunk];
}
} }