Пример #1
0
    protected override void BuildMapData(TileMapData data)
    {
        if (!tileAtlas)
        {
            throw new TileMapException("Need to setup tile map atlas!");
        }

        // create tiles
        Tile t0 = new Tile(0x01);

        t0.SetTileUvs(tileAtlas.UVsForTile(0));
        Tile t1 = new Tile(0x02);

        t1.SetTileUvs(tileAtlas.UVsForTile(1));
        Tile t2 = new Tile(0x03);

        t2.SetTileUvs(tileAtlas.UVsForTile(2));
        Tile t3 = new Tile(0x04);

        t3.SetTileUvs(tileAtlas.UVsForTile(3));

        data.AddMapTile(t0);
        data.AddMapTile(t1);
        data.AddMapTile(t2);
        data.AddMapTile(t3);

        // set random map tiles
        Debug.Log("Generating random tile data...");
        for (int r = 0; r < numRows; r++)
        {
            for (int c = 0; c < numCols; c++)
            {
                byte id;

                if (includeEmpty)
                {
                    id = (byte)Random.Range(0, 5);
                }
                else
                {
                    id = (byte)Random.Range(1, 5);
                }

                data.SetTileData(r, c, id);
            }
        }
    }
        private void InitTiles(TileMapData tileMapData)
        {
            TerrainType[] terrainTypes = MaterialPropertiesFactory.GetAllowedInitialTerrainTypes();

            float terrainSeed = Random.Range(0.0f, 200.0f);
            float heightSeed  = Random.Range(0.0f, 200.0f);

            for (int x = 0; x < _sizeX; x++)
            {
                for (int y = 0; y < _sizeY; y++)
                {
                    int   generatedType   = GenerateTerrainType(x, y, terrainSeed, terrainTypes.Length);
                    float generatedHeight = GenerateTerrainHeight(x, y, heightSeed);

                    TerrainType        terrainType        = terrainTypes[generatedType];
                    MaterialProperties materialProperties = MaterialPropertiesFactory.GetProperties(terrainType);

                    TerrainData terrainData = new TerrainData(terrainType, generatedHeight, materialProperties);
                    tileMapData.SetTileData(x, y, new TileData(x, y, terrainData));
                }
            }
        }