Add chunks
This commit is contained in:
parent
45a1f05761
commit
e68df78beb
@ -11,7 +11,7 @@ Material:
|
||||
m_Shader: {fileID: 46, guid: 0000000000000000f000000000000000, type: 0}
|
||||
m_ShaderKeywords:
|
||||
m_LightmapFlags: 4
|
||||
m_EnableInstancingVariants: 0
|
||||
m_EnableInstancingVariants: 1
|
||||
m_DoubleSidedGI: 0
|
||||
m_CustomRenderQueue: -1
|
||||
stringTagMap: {}
|
||||
|
@ -11,7 +11,7 @@ Material:
|
||||
m_Shader: {fileID: 46, guid: 0000000000000000f000000000000000, type: 0}
|
||||
m_ShaderKeywords:
|
||||
m_LightmapFlags: 4
|
||||
m_EnableInstancingVariants: 0
|
||||
m_EnableInstancingVariants: 1
|
||||
m_DoubleSidedGI: 0
|
||||
m_CustomRenderQueue: -1
|
||||
stringTagMap: {}
|
||||
|
@ -11,7 +11,7 @@ Material:
|
||||
m_Shader: {fileID: 46, guid: 0000000000000000f000000000000000, type: 0}
|
||||
m_ShaderKeywords:
|
||||
m_LightmapFlags: 4
|
||||
m_EnableInstancingVariants: 0
|
||||
m_EnableInstancingVariants: 1
|
||||
m_DoubleSidedGI: 0
|
||||
m_CustomRenderQueue: -1
|
||||
stringTagMap: {}
|
||||
|
@ -26,6 +26,9 @@ public class Lorax : MonoBehaviour {
|
||||
private int LastSeed = -1;
|
||||
private Vector3[][] TreePositions;
|
||||
|
||||
private int ChunkSize = 20;
|
||||
private GameObject[] Chunks;
|
||||
|
||||
void Start() {
|
||||
|
||||
}
|
||||
@ -48,10 +51,16 @@ public class Lorax : MonoBehaviour {
|
||||
TotalChances[x + 1] = Counter + Chances[x];
|
||||
Counter = TotalChances[x + 1];
|
||||
}
|
||||
Chunks = new GameObject[(500 / ChunkSize) * (500 / ChunkSize)];
|
||||
TreePositions = new Vector3[cap][];
|
||||
for (int y = 0; y < cap; y++) {
|
||||
TreePositions[y] = new Vector3[cap];
|
||||
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) {
|
||||
continue;
|
||||
}
|
||||
@ -79,10 +88,17 @@ public class Lorax : MonoBehaviour {
|
||||
}
|
||||
}
|
||||
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];
|
||||
}
|
||||
}
|
||||
|
Binary file not shown.
Binary file not shown.
Loading…
Reference in New Issue
Block a user