// Body of instructions to apply in every step public override DecoratorCellState[,] OnCellStep(int x, int y, DecoratorCellState[,] map) { if (map[x, y] == DecoratorCellState.False && x + 1 < map.GetLength(0) && y + 1 < map.GetLength(1) && x > 0 && y > 0) { int emptyNeighboursCells = checkNeighboursForBuildings(map, x, y); if (emptyNeighboursCells > 3 && B2BGUtils.GetRand01() < _decorationProbability) { map[x, y] = DecoratorCellState.Origin; map[x + 1, y] = DecoratorCellState.Fragment; map[x, y + 1] = DecoratorCellState.Fragment; map[x + 1, y + 1] = DecoratorCellState.Fragment; GameObject g = Instantiate(_buildings[Random.Range(0, _buildings.Length)]); GameObject parentCell = _terrainData[x, y]; Bounds bounds; if (g.GetComponent <Renderer>() == null) { bounds = g.GetComponentInChildren <Renderer>().bounds; } else { bounds = g.GetComponent <Renderer>().bounds; } g.transform.position = parentCell.transform.position; g.transform.position += new Vector3(1, 0, 1); g = RotateRandomNSEW(g); g.transform.SetParent(parentCell.transform); _decorationData[x, y] = g; } } return(map); }
public override DecoratorCellState[,] OnCellStep(int x, int y, DecoratorCellState[,] map) { if (map[x, y] == DecoratorCellState.False && x + 1 < map.GetLength(0) && y + 1 < map.GetLength(1) && x > 0 && y > 0) { if (B2BGUtils.GetRand01() < _decorationProbability) { map[x, y] = DecoratorCellState.Tree; GameObject parentCell = _terrainData[x, y]; GameObject g = Instantiate(_treesArray[Random.Range(0, _treesArray.Length)]); Bounds bounds; if (g.GetComponent <Renderer>() == null) { bounds = g.GetComponentInChildren <Renderer>().bounds; } else { bounds = g.GetComponent <Renderer>().bounds; } g.transform.position = parentCell.transform.position; g.transform.SetParent(parentCell.transform); _decorationData[x, y] = g; } } return(map); }
private DecoratorCellState[,] EdgeRoads(DecoratorCellState[,] map) { // Variable that determines if bool onXAxis = B2BGUtils.GetRand01() > 0.5; int startEdge; do { startEdge = Random.Range(12, _selectableEdge); } while (onXAxis ? map[0, startEdge] != DecoratorCellState.True : map[startEdge, 0] != DecoratorCellState.True); for (int i = 0; i < _maxDirectionalSteps; i++) { if (onXAxis) { GameObject g; // Instantiate road stripe Chunk if (map[i, startEdge] == DecoratorCellState.RoadDiagonal) { g = Instantiate(_roadSmoothChunk); map[i, startEdge] = DecoratorCellState.RoadSmooth; } else { g = Instantiate(_roadStripeChunk); map[i, startEdge] = DecoratorCellState.RoadStripe; } g.transform.position = _gen.OriginPoint.position; Bounds b = g.GetComponentInChildren <Renderer>().bounds; g.transform.position += new Vector3(startEdge * b.size.x, 0.02f, i * b.size.z); g.transform.Rotate(new Vector3(0, -90, 0)); SaveToGroundData(startEdge, i, g); } else { GameObject g; // Instantiate road stripe Chunk if (map[startEdge, i] != DecoratorCellState.True) { g = Instantiate(_roadSmoothChunk); } else { g = Instantiate(_roadStripeChunk); } map[startEdge, i] = DecoratorCellState.RoadStripe; g.transform.position = _gen.OriginPoint.position; Bounds b = g.GetComponentInChildren <Renderer>().bounds; g.transform.position += new Vector3(i * b.size.x, 0.02f, startEdge * b.size.z); SaveToGroundData(startEdge, i, g); } } return(map); }
protected GameObject RotateRandomNSEW(GameObject g) { float rotProb = B2BGUtils.GetRand01(); if (rotProb < 0.25f) { g.transform.GetChild(0).Rotate(0, 90f, 0); } if (rotProb >= 0.25f && rotProb < 0.5f) { g.transform.GetChild(0).Rotate(0, 180f, 0); } if (rotProb >= 0.5f && rotProb < 0.75f) { g.transform.GetChild(0).Rotate(0, -90f, 0); } return(g); }