void buildChunk(Vector2di positionChunk) { Vector3 positionToBuild; GameObject newChunk; positionToBuild = new Vector3(positionChunk.x * (blockXsize + 1) * scale, 0, positionChunk.y * (blockYsize + 1) * scale); //print("New chunk at " + positionToBuild); newChunk = Instantiate(chunkPrefab, positionToBuild, Quaternion.identity, gameObject.transform); chunkMap.Add(positionChunk, newChunk); newChunk.GetComponent <Chunk>().launchGeneration(this.buildingList, this.road, this.roadCrossway, this.groundPlane, blockXsize, blockYsize, scale, density); }
List <Vector2di> getChunkRadius(Vector2di fromPosition) { List <Vector2di> newChunkInView = new List <Vector2di>(); //373 305 249 int radius = 6; for (var zCircle = -radius; zCircle <= radius; zCircle++) { for (var xCircle = -radius; xCircle <= radius; xCircle++) { if (xCircle * xCircle + zCircle * zCircle < radius * radius) { newChunkInView.Add(new Vector2di(xCircle + fromPosition.x, zCircle + fromPosition.y)); } } } return(newChunkInView); }
void updateChunkView() { List <Vector2di> newChunkView; Vector2di newViewPosition; newViewPosition = get2DPositionFrom3d(this.cameraPosition.position); if (viewPosition == null || viewPosition.x != newViewPosition.x || viewPosition.y != newViewPosition.y) { viewPosition = newViewPosition; newChunkView = getChunkRadius(viewPosition); foreach (Vector2di chunkPosition in newChunkView) { if (chunkMap.ContainsKey(chunkPosition)) { if (chunkMap[chunkPosition].activeSelf == true) { this.chunkView.Remove(chunkPosition); } else { chunkMap[chunkPosition].SetActive(true); } } else { buildChunk(chunkPosition); } } foreach (Vector2di chunkPosition in this.chunkView) { chunkMap[chunkPosition].SetActive(false); } this.chunkView = newChunkView; } }
public bool Equals(Vector2di obj) { return(this.x == obj.x && this.y == obj.y); }