public IEnumerator GenerateFlatGrid(int width, int length /*, GridCoordinates startingPosition*/) { if (BlockGridRenderer.Singleton.isRendered) { BlockGridRenderer.Singleton.Clear(); } yield return(null); _grid = BlockGrid.CreateFlatGrid(width, length, BlockType.RockShale); gridGenerationProcess.progress = 1f; yield return(null); if (_grid != null) { //_grid.array[startingPosition.x, startingPosition.y].type = BlockType.Ground; _grid.startingPosition = new GridCoordinates(Mathf.RoundToInt(width / 2), 0); _grid.GetBlock(_grid.startingPosition).type = BlockType.Ground; //TODO move to MapEditor scripts if (CameraControllerOld.Singleton != null) { CameraControllerOld.Singleton.freeRoamMovingPoint.position = _grid.startingPosition.GetPositionOffset(); } } yield return(null); }
public void RenderBlockParts() { Block block = _blockRenderer.block; BlockGrid grid = BlockGridController.Singleton.grid; Block frontBlock = grid.GetBlock(block.coordinates.GetFront(grid)); Block rearBlock = grid.GetBlock(block.coordinates.GetRear(grid)); Block leftBlock = grid.GetBlock(block.coordinates.GetRight(grid)); Block rightBlock = grid.GetBlock(block.coordinates.GetLeft(grid)); /* * Debug.Log("RenderBlockParts() -> " + block.coordinates + " (" + block.type + ")" + "\n\t front: \t" + frontBlock.coordinates + " (" + frontBlock.type + ")" + "\n\t rear: \t" + rearBlock.coordinates + " (" + rearBlock.type + ")" + "\n\t left: \t" + leftBlock.coordinates + " (" + leftBlock.type + ")" + "\n\t right: \t" + rightBlock.coordinates + " (" + rightBlock.type + ")" + ); */ front.SetActive(frontBlock != null && frontBlock.type == BlockType.Ground); rear.SetActive(rearBlock != null && rearBlock.type == BlockType.Ground); left.SetActive(leftBlock != null && leftBlock.type == BlockType.Ground); right.SetActive(rightBlock != null && rightBlock.type == BlockType.Ground); }
// This finds out how many blocks adjacent to this one are the same color public void UpdateBlock() { sameColorCount = 0; for (int i = 0; i < adjacentSpaces.Length; i++) { if (grid.exists(adjacentSpaces[i])) { adjacentBlocks[i] = grid.GetBlock(adjacentSpaces[i]); if (myColor == adjacentBlocks[i].myColor) { sameColorCount++; } } } Invoke("TryPop", 0.3f); }
/// <summary> /// Adds blocks in range to loadedBlocks, creating new blocks if they don't exist yet, and calling Generate() on blocks that should be visable /// </summary> /// <param name="range"></param> private void LoadBlocks(IntRect range, bool wrap = false) { //Initialize all blocks, with a one-wide buffer edge between null blocks and generated geometry for (int x = range.Left; x <= range.Right; x++) { for (int y = range.Bottom; y <= range.Top; y++) { if (cityBlocks.BlockInRange(x, y, wrap)) { BlockGenerator currentBlock = cityBlocks.GetBlock(x, y, wrap); if (currentBlock == null) { currentBlock = CreateBlock(new Int2(x, y)); } else { currentBlock.WakeUp(); } loadedBlocks.Add(currentBlock); } } } //Generate geometry inside buffer edge IntRect generatedArea = range.Shrink(new Int2(1, 1)); for (int x = generatedArea.Left; x <= generatedArea.Right; x++) { for (int y = generatedArea.Bottom; y <= generatedArea.Top; y++) { if (cityBlocks.BlockInRange(x, y, wrap) && cityBlocks.GetBlock(x, y, wrap) != null) { BlockGenerator[,] surroundingBlocks = cityBlocks.GetAdjacentBlocks(x, y, wrap); List <Vector3> surroundingPoints = new List <Vector3>(); for (int i = 0; i < 3; i++) //Loop through surroundingBlocks { for (int j = 0; j < 3; j++) { if (!(i == 1 && j == 1)) //Skip middle block because it is the active one { if (surroundingBlocks[i, j] != null && surroundingBlocks[i, j].pointsSet == true) //If the block exists and has been initialized { //Debug.Log("Block at " + cityBlocks.GetBlock(x, y).indexPosition + " is surrounded by " + surroundingBlocks[i, j].indexPosition); //Offset each point in pointlist by the position of the surrounding block relative to the center Vector3[] pointList = surroundingBlocks[i, j].pointList; List <Vector3> offsetPointlist = new List <Vector3>(); for (int point = 0; point < pointList.Length; point++) { Vector3 offset = new Vector3((i - 1) * blockSize, 0f, (j - 1) * blockSize); offsetPointlist.Add(pointList[point] + offset); } surroundingPoints.AddRange(offsetPointlist); } } } } cityBlocks.GetBlock(x, y, wrap).Generate(surroundingPoints.ToArray()); } } } }