Ejemplo n.º 1
0
    public void OnDestroy()
    {
        //generate and safe terrain and colormaps for the next run

        Terrain terrain = this.GetComponent <Terrain>();

        data = terrain.terrainData;
        data.heightmapResolution = width;
        data.size           = new Vector3(width, height, depth);
        terrain.terrainData = GenerateTerrain(terrain.terrainData);

        Blending  blender = new Blending();                         //init blender
        Texture2D grass   = Resources.Load("gras15") as Texture2D;  //1
        Texture2D wood    = Resources.Load("Holz-34") as Texture2D; //2
        Texture2D mud     = Resources.Load("mud02") as Texture2D;   //3
        Texture2D stone   = Resources.Load("rock8") as Texture2D;   //4

        Color[,] colorArray = blender.generateBlend(grass, wood, mud, stone, terrain.terrainData, width, height);

        //use this colorArray to calculate a texture and apply it to the terrain
        Texture2D image = new Texture2D(width, height);

        for (int y = 0; y < height; y++)
        {
            for (int x = 0; x < width; x++)
            {
                image.SetPixel(x, y, colorArray[x, y]);
            }
        }

        //save pic
        var Bytes = image.EncodeToPNG();

        File.WriteAllBytes(Application.dataPath + "/Resources/TerrainColorMap.png", Bytes);
    }
    // Use this for initialization
    void Start()
    {
        offX = Random.Range(0f, 999f);
        offY = Random.Range(0f, 999f);

        Terrain terrain = GetComponent <Terrain>();//getting the terrain
        //terrain.terrainData = generateTerrain(terrain.terrainData);

        Blending  blender = new Blending();                           //init blender
        Texture2D grass   = Resources.Load("greenLawn") as Texture2D; //1
        Texture2D wood    = Resources.Load("Holz-34") as Texture2D;   //2
        Texture2D mud     = Resources.Load("mud02") as Texture2D;     //3
        Texture2D stone   = Resources.Load("rock8") as Texture2D;     //4

        Color[,] colorArray = blender.generateBlend(grass, wood, mud, stone, terrain.terrainData, width, height);

        //use this colorArray to calculate a texture and apply it to the terrain
        Texture2D image = new Texture2D(width, height);

        for (int y = 0; y < height; y++)
        {
            for (int x = 0; x < width; x++)
            {
                image.SetPixel(x, y, colorArray[x, y]);
            }
        }

        //save pic
        var Bytes = image.EncodeToPNG();

        File.WriteAllBytes(Application.dataPath + "/Resources/TerrainColorMap.png", Bytes);
    }