public override GameObject GenerateAreaScenery(Terrain terrain) { var result = new GameObject(Name); // Generate trees taking buildings into consideration foreach (var areaData in AreaDataGraph.GetAllNodeData()) { // Poisson filling PoissonDiskFillData poissonData = new PoissonDiskFillData(Trees, areaData.Polygon, TreeDistance, AngleTolerance, true); poissonData.AddClearPolygons(ClearPolygons); PoissonDataList.Add(poissonData); // Place arenas - skip start position if (areaData.Segment.Type == AreaSegment.EAreaSegmentType.Start) { continue; } var arena = PlaceArena(areaData, terrain); arena.transform.parent = result.transform; } return(result); }
public override GameObject GenerateAreaScenery(Terrain terrain) { var result = new GameObject(Name); // Place lamps var lamps = PlaceStreetLamps(terrain); lamps.transform.parent = result.transform; // Place buildings var buildings = PlaceBuildings(terrain); buildings.transform.parent = result.transform; // Generate trees taking buildings into consideration foreach (var areaData in AreaDataGraph.GetAllNodeData()) { // Poisson filling PoissonDiskFillData poissonData = new PoissonDiskFillData(Trees, areaData.Polygon, TreeDistance, TreeAngleTolerance, true); poissonData.AddClearPolygons(ClearPolygons); PoissonDataList.Add(poissonData); // Place arenas var arena = PlaceArena(areaData, terrain); arena.transform.parent = result.transform; } return(result); }
// Place buildings throughout all area segments private GameObject PlaceBuildings(Terrain terrain) { GameObject result = new GameObject("Buildings"); var unique = new List <GameObject>(UniqueBuildings); // Fill each node with buildings around the roads foreach (var nodeData in AreaDataGraph.GetAllNodeData()) { var fill = FillAreaSegment(nodeData, unique, terrain); fill.transform.parent = result.transform; } return(result); }
private GameObject PlaceStreetLamps(Terrain terrain) { var result = new GameObject("Lamps"); List <Vector2[]> pathLines = new List <Vector2[]>(); // Collect all roads foreach (var areaData in AreaDataGraph.GetAllNodeData()) { var data = areaData; var validPaths = areaData.Paths.Where(path => path.All(vtx => vtx.IsInsidePolygon(data.Polygon))).ToList(); pathLines = pathLines.Union(validPaths).ToList(); } // Place lamps along the paths, alternating side and skipping one bool spawnRight = true; bool skip = true; foreach (var line in pathLines) { skip = !skip; if (skip) { continue; } var pathCenter = (line[0] + line[1]) / 2f; var normal = spawnRight ? (Vector2)Vector3.Cross(line[0] - line[1], Vector3.back).normalized : (Vector2)Vector3.Cross(line[0] - line[1], Vector3.forward).normalized; var position2D = pathCenter + normal * LampPathOffset; var position = new Vector3(position2D.x, 0, position2D.y); var rotation = Quaternion.LookRotation(new Vector3(pathCenter.x, 0, pathCenter.y) - position, Vector3.up); position += new Vector3(0, terrain.SampleHeight(position), 0); var lamp = Object.Instantiate(StreetLamp, position, rotation); lamp.CorrectAngleTolerance(LampAngleTolerance); lamp.transform.parent = result.transform; var lampClear = lamp.GetComponent <BoxCollider>().Get2DPolygon(); ClearPolygons.Add(lampClear.OffsetToCenter(lampClear.GetPolygonCenter(), -1).ToArray()); // Flip side spawnRight = !spawnRight; } return(result); }
public override GameObject GenerateAreaScenery(Terrain terrain) { var arena = new GameObject(Name); // Find boss area center Vector2 center = Vector2.zero; var allData = AreaDataGraph.GetAllNodeData(); foreach (var areaData in allData) { center += areaData.Center; } center /= allData.Length; // Split gate line var skip = SplitEntranceLine(BorderPolygon); BorderPolygon = BorderPolygon.OffsetToCenter(center, 8, skip).ToList(); // Generate gate var line = _gateLine[0] - _gateLine[1]; var gatePosition2D = (_gateLine[0] + _gateLine[1]) / 2; var gatePosition = new Vector3(gatePosition2D.x, 0, gatePosition2D.y); // Set arena center on gate script var arenaCenter2D = center; // Place portal var portalPosition = new Vector3(arenaCenter2D.x, 0, arenaCenter2D.y); portalPosition += new Vector3(0, terrain.SampleHeight(portalPosition), 0); var portal = Object.Instantiate(_portalPrefab, portalPosition, terrain.GetNormalRotation(portalPosition) * Quaternion.LookRotation(gatePosition - new Vector3(portalPosition.x, 0, portalPosition.z), Vector3.up)); portal.transform.parent = arena.transform; // Generate Walls var lines = BorderPolygon.PolygonToLines(skip); var walls = LevelDataGenerator.GenerateBlockerLine(terrain, lines, _wallLenght, _wallPositionNoise, _wallScaleNoise, _wallPrefab, false, _towerPrefab, _wallAngleLimit); walls.transform.parent = arena.transform; // Generate last tower next to the gate var gateTower = Object.Instantiate(_towerPrefab); gateTower.transform.position = gatePosition + Quaternion.LookRotation(new Vector3(line.x, 0, line.y), Vector3.up) * new Vector3(0, 0, line.magnitude / 2); gateTower.transform.position += new Vector3(0, terrain.SampleHeight(gateTower.transform.position), 0); gateTower.transform.rotation = terrain.GetNormalRotation(gateTower.transform.position); gateTower.CorrectAngleTolerance(_wallAngleLimit); gateTower.transform.parent = arena.transform; var navMeshModifier = gateTower.AddComponent <NavMeshModifier>(); navMeshModifier.overrideArea = true; navMeshModifier.area = NavMesh.GetAreaFromName("Not Walkable"); // Spawn boss at the arena center var bossPosition = new Vector3(portalPosition.x, 0, portalPosition.z) + 5 * new Vector3(gatePosition.x - portalPosition.x, 0, gatePosition.z - portalPosition.z).normalized; bossPosition += new Vector3(0, terrain.SampleHeight(bossPosition), 0); var boss = Object.Instantiate(_bossPrefab, bossPosition, Quaternion.identity); boss.transform.parent = arena.transform; var bossTrigger = boss.AddComponent <PortalActivateTrigger>(); bossTrigger.Portal = portal; bossTrigger.Initialize(); return(arena); }