//// Water Plane Placement //private void GenerateWaterPlane() //{ // var water = GameObject.CreatePrimitive(PrimitiveType.Plane); // water.name = "Water"; // water.GetComponent<Collider>().enabled = false; // water.GetComponent<Renderer>().material = WaterMaterial; // water.GetComponent<Renderer>().shadowCastingMode = ShadowCastingMode.Off; // water.transform.localScale = new Vector3(Terrain.terrainData.size.x / 5f, 1, Terrain.terrainData.size.z / 5f); // water.transform.parent = transform; // water.transform.localPosition = new Vector3(Terrain.terrainData.size.x / 2f, (WaterHeight + 0.01f) * Terrain.terrainData.size.y, Terrain.terrainData.size.z / 2f); //} // Add fences to coast and walls between non crossable area segment borders private void GenerateBlockers() { var borderSettings = MyTerrainStructure.BorderSettings; var fences = LevelDataGenerator.GenerateBlockerLine(Terrain, MyTerrainStructure.BorderBlockerLines, borderSettings.BlockerLength, borderSettings.BlockerPositionNoise, borderSettings.BlockerScaleNoise, borderSettings.Blocker, false, borderSettings.BlockerPole, borderSettings.BlockerAngleLimit); fences.transform.parent = transform; var biomeSettings = MyTerrainStructure.BiomeSettings; var walls = LevelDataGenerator.GenerateBlockerLine(Terrain, MyTerrainStructure.AreaBlockerLines, biomeSettings.BlockerLength, biomeSettings.BlockerPositionNoise, biomeSettings.BlockerScaleNoise, biomeSettings.Blocker, true, biomeSettings.BlockerPole, biomeSettings.BlockerAngleLimit); walls.transform.parent = transform; }
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); }