public override void OnInspectorGUI()
    {
        bool changed = DrawDefaultInspector();

        autoUpdate = EditorGUILayout.Toggle("Auto Update", autoUpdate);
        if ((changed && autoUpdate) || GUILayout.Button("Generate"))
        {
            NoisemapGenerator generator = (NoisemapGenerator)target;
            float[,] heightmap = generator.GenerateNoisemap();
            texture            = Texture2DUtility.FromNoisemap(heightmap);
        }

        if (texture != null && GUILayout.Button("Save as png"))
        {
            File.WriteAllBytes("Assets/texture.png", texture.EncodeToPNG());
        }

        if (texture != null)
        {
            GUILayout.Box(texture);
        }
    }
示例#2
0
    private void Update()
    {
        float[,] noiseMap = NoisemapGenerator.computeNoiseMap(
            this.noiseSettings,
            this._seed.GetHashCode(),
            this._mapSize,
            0);

        // Color the tilemap.
        for (int x = 0; x < this._mapSize; x++)
        {
            for (int y = 0; y < this._mapSize; y++)
            {
                float f = noiseMap[x, y];

                Color c = gradient.Evaluate(f);
                //c = new Color(f, f, f);

                this.tilemap.SetColor(new Vector3Int(x, y, 0), c);
            }
        }
    }
示例#3
0
    /// <summary>
    /// Fully generates the Layer at the passed depth and places it
    /// into the World's storage.
    /// </summary>
    public void generateLayer(World world, int depth)
    {
        int layerSeed = world.seed * (depth + 1);

        MapAccessor accessor  = new MapAccessor(world.mapSize, depth);
        LayerData   layerData = this.getLayerFromDepth(depth);


        // Fill the map with the Layer's fill cell.
        for (int x = 0; x < accessor.size; x++)
        {
            for (int y = 0; y < accessor.size; y++)
            {
                accessor.setCell(x, y, layerData.getFillCell(world, x, y));
            }
        }


        // Generate all of the features.
        foreach (FeatureBase feature in this.features)
        {
            feature.generate(new System.Random(layerSeed), layerData, accessor);
        }


        Layer layer = new Layer(world, depth);


        // Apply the accessor to the Layer.
        for (int x = 0; x < accessor.size; x++)
        {
            for (int y = 0; y < accessor.size; y++)
            {
                Rotation r = accessor.getRot(x, y);
                layer.setCell(
                    x,
                    y,
                    accessor.getCell(x, y),
                    r == null ? Rotation.UP : r,
                    false);
            }
        }


        // Generate the hardness map and apply it.
        float[,] noise = NoisemapGenerator.computeNoiseMap(
            this._noiseSettings,
            world.seed,
            world.mapSize,
            depth);
        for (int x = 0; x < world.mapSize; x++)
        {
            for (int y = 0; y < world.mapSize; y++)
            {
                float n        = noise[x, y];
                int   hardness = n < 0.333f ? 0 : (n < 0.666f ? 1 : 2);
                layer.setHardness(x, y, hardness);
            }
        }


        world.storage.setLayer(layer, depth);


        // Generate all of the structures that belong on this Layer
        Random.InitState(layerSeed);

        foreach (StructureBase structure in layerData.structures)
        {
            if (structure != null)
            {
                structure.generate(world, depth);
            }
        }
    }