Ejemplo n.º 1
0
        /// <summary>
        /// Export the NoiseProfile(s) to the Application.persistantData Folder
        /// </summary>
        /// <param name="type">NoiseProfile Type</param>
        /// <param name="filename"></param>
        /// <param name="noiseProfiles">List of Noise Profiles</param>
        /// <param name="mixedTexture">this is the mixed final texted is using arithmetic</param>
        /// <returns></returns>
        public static bool ExportNoiseProfiles(NoiseClass.NoiseType type, string filename, List <NoiseProfileOptions> noiseProfiles, Texture2D mixedTexture)
        {
            Debug.Log("Exporting Noise Profile...");
            string saveLocation = path + NoiseClass.Type2String(type) + "/" + filename + "/";

            if (!CheckAndCreateDirectoryIfMissing(path))
            {
                ExportNoiseProfiles(type, filename, noiseProfiles, mixedTexture);
            }
            else if (!CheckAndCreateDirectoryIfMissing(path + NoiseClass.Type2String(type)))
            {
                ExportNoiseProfiles(type, filename, noiseProfiles, mixedTexture);
            }
            else if (!CheckAndCreateDirectoryIfMissing(path + NoiseClass.Type2String(type) + "/" + filename))
            {
                ExportNoiseProfiles(type, filename, noiseProfiles, mixedTexture);
            }
            else
            {
                if (type == NoiseClass.NoiseType.Mixed)
                {
                    // lets save the mixedTexture first
                    Texture2D text = NoiseClass.CopyTexture2D(mixedTexture);
                    //	SaveHeightMap(type, saveLocation + filename + ".map", mixedTexture, true);
                    // Now we will save each noise profile and its values in seperate folders
                    SaveNoiseProfiles(noiseProfiles, saveLocation);
                    SavePng(text, saveLocation + filename + ".png");
                }
                else
                {
                    int index = 0;
                    // we need to find the enabled profile
                    for (int i = 0; i < noiseProfiles.Count; i++)
                    {
                        if (noiseProfiles[i].profileMode == NoiseClass.NoiseProfileMode.Texture)
                        {
                            index = i;
                            break;
                        }
                    }

                    SaveNoiseProfileV2(saveLocation + filename + ".dat", noiseProfiles[index]);

                    Texture2D text = noiseProfiles[index].GetTexture();
                    SavePng(text, saveLocation + filename + ".png");
                    Debug.Log("Successfully Exported Noise Profiles!");
                }
            }

            return(false);
        }
Ejemplo n.º 2
0
    public void GenerateMap()
    {
        float[,] noiseMap = NoiseClass.GenerateNoiseMap(mapChunkSize, mapChunkSize, seed, scale, octaves, persistance, lacunarity, offset);

        Color[] colorMap = new Color[mapChunkSize * mapChunkSize];

        for (int i = 0; i < mapChunkSize; ++i)
        {
            for (int j = 0; j < mapChunkSize; ++j)
            {
                float currHeight = noiseMap[i, j];
                for (int k = 0; k < terrainRegions.Length; ++k)
                {
                    if (currHeight <= terrainRegions[k].height)
                    {
                        colorMap[i * mapChunkSize + j] = terrainRegions[k].color;
                        break;
                    }
                }
            }
        }

        MapDisplay mapDisplay = FindObjectOfType <MapDisplay>();

        switch (drawMode)
        {
        case DrawMode.NoiseMap:
            mapDisplay.DrawTexture(TextureGenerator.TextureFromNoisetMap(noiseMap));
            break;

        case DrawMode.ColorMap:
            mapDisplay.DrawTexture(TextureGenerator.TextureToColorMap(colorMap, mapChunkSize, mapChunkSize));
            break;

        case DrawMode.DrawMesh:
            mapDisplay.DrawMesh(MeshGenerator.GenerateTerrainMesh(noiseMap, heightMultiplier, meshHeigthCurve, leveleOfDetail), TextureGenerator.TextureToColorMap(colorMap, mapChunkSize, mapChunkSize));
            break;

        default:
            mapDisplay.DrawTexture(TextureGenerator.TextureFromNoisetMap(noiseMap));
            break;
        }
    }