public void GenerateIsland()
    {
        if (useRandomSeed)
        {
            seed = System.DateTime.Now.ToString();
        }

        int seedHash = seed.GetHashCode();

        System.Random pseudoRandom = new System.Random(seedHash);

        map = new LandMap(islandData.maxWidth, islandData.maxHeight);

        // Fill the map randomly with 0s and 1s based on percentage fill
        map.RandomFillMap(ref pseudoRandom, islandData.randomFillPercent);

        // Smooth the map 5 times
        map.SmoothMap(5);

        // Create separate islands
        PartitionIslands();

        if (shouldElevate)
        {
            foreach (IsleInfo island in islands)
            {
                island.surfaceMeshRegion.CalculateGradientMap();
            }

            ElevationGenerator elevGen = GetComponent <ElevationGenerator> ();
            elevGen.elevateSurface(islands, islandData.altitude, islandData.mountainCurve, surfaceNoiseData, seedHash, 0);   // elevate hills on the surface
            elevGen.elevateSurface(islands, -islandData.stalactite, islandData.bellyCurve, undersideNoiseData, seedHash, 2); // extend stakes at surface below
        }

        SetColliders();

        PlacementGenerator placement = GetComponent <PlacementGenerator> ();

        if (placement && decorateTerrain)
        {
            placement.GeneratePlacement(islands, ref pseudoRandom);
        }

        if (flatShading)
        {
            foreach (IsleInfo island in islands)
            {
                for (int surfaceIndex = 0; surfaceIndex < 3; surfaceIndex++)
                {
                    MeshFilter mf           = island.GetSurfaceMesh(surfaceIndex);
                    float      oldVertCount = mf.sharedMesh.vertexCount;
                    mf.sharedMesh = FlatShade.DuplicateSharedVertex(mf.sharedMesh);
                    float newVertCount = mf.sharedMesh.vertexCount;
                    //Debug.Log (mf.transform.parent.name + "." + mf.transform.name + " new vertices are at " + (newVertCount / oldVertCount * 100) + "% with " + newVertCount + " verts.");
                }
            }
        }
    }
    void GenerateInEditor()
    {
        if (!Application.isPlaying)
        {
            finished = false;

            if (useRandomSeed)
            {
                seed = DateTime.Now.ToString();
            }

            Random.State oldState = Random.state;
            int          seedHash = seed.GetHashCode();
            Random.InitState(seedHash);

            for (int i = 0; i < randCol.Length; i++)
            {
                randCol[i] = Random.ColorHSV(0, 1, 0, 1, 0.5f, 1);
            }

            map = new LandMap(islandData.maxWidth, islandData.maxHeight);

            // Fill the map randomly with 0s and 1s based on percentage fill
            map.RandomFillMap(islandData.randomFillPercent);

            // Mold to the base shape
            if (islandData.baseShape)
            {
                map.makeBaseShape(islandData.baseShape);
            }

            // Smooth the map 5 times
            map.SmoothMap(5);

            meshGen = GetComponent <IslandMeshGenerator> ();
            vertDatabase.Clear();
            vertDatabase.tileSize = islandData.tileSize;

            // Find separated regions to form an island
            List <MapRegion> regions = map.GetRegions();

            // Create separate islands
            SeparateIslands(regions);

            clk.Start();
            vertDatabase.SetCoordDB();
            Debug.Log("Indexing takes " + clk.Elapsed() + " seconds.");

            if (shouldElevate)
            {
                int highestPeak = 0;
                foreach (IsleInfo island in islands)
                {
                    int peak = island.surfaceMeshDetail.localPeak;
                    highestPeak = peak > highestPeak ? peak : highestPeak;
                }
                foreach (IsleInfo island in islands)
                {
                    island.surfaceMeshDetail.NormalizeGradientMap(highestPeak);
                }

                vertDatabase.SetVerticesInlandPos(islands, islandData.mountainCurve);

                ElevationGenerator elevGen = GetComponent <ElevationGenerator> ();
                elevGen.elevateSurface(islands, islandData.altitude, islandData.mountainCurve, surfaceNoiseData, seedHash, 0, vertDatabase);    // elevate hills on the surface
                elevGen.elevateSurface(islands, -islandData.stalactite, islandData.bellyCurve, undersideNoiseData, seedHash, 2, vertDatabase);  // extend stakes at surface below
            }

            clk.Start();
            int zoneNum = DoClustering(regions, map.spots, vertDatabase, clusterAnalysis, seedHash);
            Debug.Log("Clustering takes " + clk.Elapsed() + " seconds.");

            // Find strategic locations in each region
            List <MapRegion> zones = map.GetZones(zoneNum);
            SpliceTerritory(zones);

            SetColliders();

            PlacementGenerator placement = GetComponent <PlacementGenerator> ();
            if (placement && decorateTerrain)
            {
                placement.GenerateTrees(islands);
                placement.GenerateSectorsContent(sectors, vertDatabase);
            }
            else if (placement)
            {
                //placement.GeneratePlacements (islands);
                placement.GenerateSectorsContent(sectors, vertDatabase);
            }

            if (flatShading)
            {
                foreach (IsleInfo island in islands)
                {
                    for (int surfaceIndex = 0; surfaceIndex < 3; surfaceIndex++)
                    {
                        MeshFilter mf           = island.GetSurfaceMesh(surfaceIndex);
                        float      oldVertCount = mf.sharedMesh.vertexCount;
                        mf.sharedMesh = FlatShade.DuplicateSharedVertex(mf.sharedMesh);
                        float newVertCount = mf.sharedMesh.vertexCount;
                        //Debug.Log (mf.transform.parent.name + "." + mf.transform.name + " new vertices are at " + (newVertCount / oldVertCount * 100) + "% with " + newVertCount + " verts.");
                    }
                }
            }

            Random.state = oldState;
        }
    }