// Draw roads on alpha map private void GeneratePaths() { LevelDataGenerator.DrawStraightPathLines(_heightMap, _alphaMap, MyTerrainStructure.BiomeSettings.SidePathSplatSize, MapSize, HeightMapResolution, MyTerrainStructure.SidePathLines, MyTerrainStructure.TextureCount, MyTerrainStructure.SidePathSplatIndex); LevelDataGenerator.DrawStraightPathLines(_heightMap, _alphaMap, MyTerrainStructure.BiomeSettings.MainPathSplatSize, MapSize, HeightMapResolution, MyTerrainStructure.MainPathLines, MyTerrainStructure.TextureCount, MyTerrainStructure.MainPathSplatIndex); }
//--------------------------------------------------------------- // GENERATING FUNCTIONS //--------------------------------------------------------------- // Generate alpha and height maps private void GenerateAlphaAndHeightmaps() { // Create heightmap _heightMap = LevelDataGenerator.GenerateHeightMap(MyTerrainStructure); // Create splat textures alphamap _alphaMap = LevelDataGenerator.GenerateAlphaMap(MyTerrainStructure); }
private void SmoothAlphaMap() { // Smoothing passes for (int i = 0; i < OverallAlphaSmoothPasses; i++) { _alphaMap = LevelDataGenerator.SmoothAlphaMap(_alphaMap, OverallAlphaSmoothSquareSize); } //GPU version -> slightly offset and looks bit different?, but seems to work //LevelDataGenerator.SmoothHeightMap(_alphaMap, OverallAlphaSmoothSquareSize, OverallAlphaSmoothPasses); }
//// 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; }
private void Start() { if (shouldUseSeed.Value) { Debug.Log($"Initializing game with seed {seedValue.Value}"); Random.InitState(seedValue.Value.GetHashCode()); } LevelBuildData data = LevelDataGenerator.CreateNewLevel(allThemes[0]); Level.Current = LevelBuilder.Build(data); player.transform.position = data.SpawnPosition; shouldUseSeed.Value = false; }
private void SmoothHeightMap() { // Overall smoothing //for(int i = 0; i < OverallSmoothPasses; i++) //{ // LevelDataGenerator.SmoothHeightMap(_heightMap, OverallSmoothSquareSize); //} //GPU smooth: LevelDataGenerator.SmoothHeightMap(_heightMap, OverallSmoothSquareSize, OverallSmoothPasses); // Smooth paths for (int i = 0; i < PathSmoothPasses; i++) { LevelDataGenerator.SmoothHeightMapWithLines(_heightMap, MapSize / HeightMapResolution, MyTerrainStructure.MainPathLines, MyTerrainStructure.BiomeSettings.MainPathSplatSize, PathSmoothSquaresize); LevelDataGenerator.SmoothHeightMapWithLines(_heightMap, MapSize / HeightMapResolution, MyTerrainStructure.SidePathLines, MyTerrainStructure.BiomeSettings.SidePathSplatSize, PathSmoothSquaresize); } }
// Fill terrain with scenery private void GenerateScenery() { var sceneryObjects = LevelDataGenerator.GenerateScenery(Terrain.GetComponent <Terrain>(), MySceneryStructure.Areas); var scenery = new GameObject("Scenery"); scenery.transform.parent = transform; foreach (var obj in sceneryObjects) { obj.transform.parent = scenery.transform; } // Attach particle system to camera if (!Application.isEditor) { var ps = Instantiate(MyTerrainStructure.BiomeSettings.FallingParticlesPrefab); ps.transform.parent = mainCamera.transform; ps.transform.localPosition = Vector3.zero; ps.transform.localRotation = Quaternion.Inverse(mainCamera.transform.rotation); } }
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); }