// -----------------------------------------------------------------------------------
        //
        // -----------------------------------------------------------------------------------
        public override void OnInspectorGUI()
        {
            //store the object the original Inspector in a variable of the same type:
            LevelGeneration generator = (LevelGeneration)target;

            DrawDefaultInspector();

            GUI.color = Color.red;
            GUILayout.Space(10);

            if (GUILayout.Button("Delete Terrain"))
            {
                generator.DeleteMap(true);
            }

            GUI.color = Color.green;
            GUILayout.Space(10);

            if (GUILayout.Button("Generate Terrain"))
            {
                generator.GenerateMap();
            }
        }
Ejemplo n.º 2
0
        // -----------------------------------------------------------------------------------
        //
        // -----------------------------------------------------------------------------------
        public TileData GenerateTile(LevelGeneration _levelGeneration)
        {
            // setup dependencies
            root = _levelGeneration;
            noiseMapGeneration.root = root;

            // calculate tile depth and width based on the mesh vertices
            meshVertices = meshFilter.sharedMesh.vertices;
            tileSize     = (int)Mathf.Sqrt(meshVertices.Length);

            // calculate the offsets based on the tile position
            offsetX = -this.gameObject.transform.position.x;
            offsetZ = -this.gameObject.transform.position.z;


            // calculate vertex offset based on the Tile position and the distance between vertices
            Vector3 tileDimensions          = meshFilter.sharedMesh.bounds.size;
            float   distanceBetweenVertices = tileDimensions.z / (float)tileSize;

            vertexOffset = this.gameObject.transform.position.z / distanceBetweenVertices;

            GenerateHeightMap();
            GenerateHeatMap();
            GenerateMoistureMap();
            GenerateDifficultyMap();

            // ------- build all textures ---------


            // build a Texture2D from the height map
            HeightTemplate[,] chosenHeightTypes = new HeightTemplate[tileSize, tileSize];
            heightTexture = BuildTexture(heightMap, root.heightSettings.templates, chosenHeightTypes);

            // build a Texture2D from the heat map
            TemperatureTemplate[,] chosenHeatTypes = new TemperatureTemplate[tileSize, tileSize];
            heatTexture = BuildTexture(heatMap, root.temperatureSettings.templates, chosenHeatTypes);

            // build a Texture2D from the moisture map
            MoistureTemplate[,] chosenMoistureTypes = new MoistureTemplate[tileSize, tileSize];
            moistureTexture = BuildTexture(moistureMap, root.moistureSettings.templates, chosenMoistureTypes);

            // build a Texture2D from the difficulty map
            DifficultyTemplate[,] chosenDifficultyTypes = new DifficultyTemplate[tileSize, tileSize];
            difficultyTexture = BuildTexture(difficultyMap, root.difficultySettings.templates, chosenDifficultyTypes);

            // build a biomes Texture2D from the three other noise variables
            BiomeTemplate[,] chosenBiomes = new BiomeTemplate[tileSize, tileSize];
            biomeTexture = BuildBiomeTexture(chosenHeightTypes, chosenHeatTypes, chosenMoistureTypes, chosenDifficultyTypes, chosenBiomes);

            // -------

            // update the visualization mode
            UpdateVisualizationMode();



            // update the tile mesh vertices according to the height map
            UpdateMeshVertices(heightMap);

            TileData tileData = new TileData(heightMap, heatMap, moistureMap, difficultyMap,
                                             chosenHeightTypes, chosenHeatTypes, chosenMoistureTypes, chosenDifficultyTypes, chosenBiomes,
                                             meshFilter.mesh, (Texture2D)this.tileRenderer.sharedMaterial.mainTexture);

            return(tileData);
        }