Exemple #1
0
    public override void OnInspectorGUI()
    {
        DisplayNoise displayNoise = (DisplayNoise)target;

        DrawDefaultInspector();

        if (GUILayout.Button("Generate"))
        {
            displayNoise.generateNoise();
        }
    }
Exemple #2
0
    public void GenerateMap()
    {
        float[,] noiseMap = PerlinNoise.NoiseMap(
            mapWidth,
            mapHeight,
            seed,
            noiseScale,
            octaves,
            amplitude,
            frequency,
            offset);

        Color[] colorMode = new Color[mapWidth * mapHeight];
        for (int y = 0; y < mapHeight; y++)
        {
            for (int x = 0; x < mapWidth; x++)
            {
                float currentHeight = noiseMap [x, y];
                for (int i = 0; i < heights.Length; i++)
                {
                    if (currentHeight <= heights [i].height)
                    {
                        colorMode [y * mapWidth + x] = heights [i].colour;
                        break;
                    }
                }
            }
        }

        DisplayNoise display = FindObjectOfType <DisplayNoise> ();

        if (displayMode == DisplayMode.NoiseMap)
        {
            display.DrawTexture(Textures.HeightMapTexture(noiseMap));
        }
        else if (displayMode == DisplayMode.ColourMap)
        {
            display.DrawTexture(Textures.ColorTexture(
                                    colorMode,
                                    mapWidth,
                                    mapHeight
                                    ));
        }
    }