public void SetTile(Autotiler.Tiles tiles) { this.tiles = tiles; }
public void GenerateTiles(Tilemap tilemap, VirtualMap <char> foregroundData, int startX, int startY, int tilesX, int tilesY, bool forceSolid, char forceID, Autotiler.Behaviour behaviour, ColliderGrid colliderGrid) { Rectangle forceFill = Rectangle.Empty; if (forceSolid) { forceFill = new Rectangle(startX, startY, tilesX, tilesY); } if (foregroundData != null) { for (int x1 = startX; x1 < startX + tilesX; x1 += 50) { for (int y1 = startY; y1 < startY + tilesY; y1 += 50) { if (!foregroundData.AnyInSegmentAtTile(x1, y1)) { y1 = y1 / 50 * 50; } else { int x2 = x1; for (int index1 = Math.Min(x1 + 50, startX + tilesX); x2 < index1; ++x2) { int y2 = y1; for (int index2 = Math.Min(y1 + 50, startY + tilesY); y2 < index2; ++y2) { Autotiler.Tiles tiles = this.TileHandler(foregroundData, x2, y2, forceFill, forceID, behaviour); if (tiles != null) { SolidTile tile = ScriptableObject.CreateInstance <SolidTile>(); tile.SetTile(tiles); tile.colliderType = colliderGrid[x2 - startX, y2 - startY]? Tile.ColliderType.Grid:Tile.ColliderType.None; tilemap.SetTile(new Vector3Int(x2 - startX, -(y2 - startY), 0), tile); //this.tilemap.SetTile(new Vector3Int(0, 0, 0), tile); //return; } //if (tiles != null) //{ // tileGrid.Tiles[x2 - startX, y2 - startY] = RandomUtil.Random.Choose<MTexture>(tiles.Textures); // //if (tiles.HasOverlays) // // animatedTiles.Set(x2 - startX, y2 - startY, RandomUtil.Random.Choose<string>(tiles.OverlapSprites), 1f, 1f); //} } } } } } } else { for (int x = startX; x < startX + tilesX; ++x) { for (int y = startY; y < startY + tilesY; ++y) { Autotiler.Tiles tiles = this.TileHandler((VirtualMap <char>)null, x, y, forceFill, forceID, behaviour); if (tiles != null) { SolidTile tile = ScriptableObject.CreateInstance <SolidTile>(); tile.SetTile(tiles); tile.colliderType = colliderGrid[x - startX, y - startY] ? Tile.ColliderType.Grid : Tile.ColliderType.None; tilemap.SetTile(new Vector3Int(x - startX, -(y - startY), 0), tile); //this.tilemap.SetTile(new Vector3Int(0, 0, 0), tile); //return; } //if (tiles != null) //{ // tileGrid.Tiles[x - startX, y - startY] = RandomUtil.Random.Choose<MTexture>(tiles.Textures); // if (tiles.HasOverlays) // animatedTiles.Set(x - startX, y - startY, RandomUtil.Random.Choose<string>(tiles.OverlapSprites), 1f, 1f); //} } } } }
private Autotiler.Generated Generate( VirtualMap <char> mapData, int startX, int startY, int tilesX, int tilesY, bool forceSolid, char forceID, Autotiler.Behaviour behaviour) { TileGrid tileGrid = new TileGrid(8, 8, tilesX, tilesY); AnimatedTiles animatedTiles = new AnimatedTiles(tilesX, tilesY, Gfx.AnimatedTilesBank); Rectangle forceFill = Rectangle.Empty; if (forceSolid) { forceFill = new Rectangle(startX, startY, tilesX, tilesY); } if (mapData != null) { for (int x1 = startX; x1 < startX + tilesX; x1 += 50) { for (int y1 = startY; y1 < startY + tilesY; y1 += 50) { if (!mapData.AnyInSegmentAtTile(x1, y1)) { y1 = y1 / 50 * 50; } else { int x2 = x1; for (int index1 = Math.Min(x1 + 50, startX + tilesX); x2 < index1; ++x2) { int y2 = y1; for (int index2 = Math.Min(y1 + 50, startY + tilesY); y2 < index2; ++y2) { Autotiler.Tiles tiles = this.TileHandler(mapData, x2, y2, forceFill, forceID, behaviour); if (tiles != null) { tileGrid.Tiles[x2 - startX, y2 - startY] = RandomUtil.Random.Choose <MTexture>(tiles.Textures); if (tiles.HasOverlays) { animatedTiles.Set(x2 - startX, y2 - startY, RandomUtil.Random.Choose <string>(tiles.OverlapSprites), 1f, 1f); } } } } } } } } else { for (int x = startX; x < startX + tilesX; ++x) { for (int y = startY; y < startY + tilesY; ++y) { Autotiler.Tiles tiles = this.TileHandler((VirtualMap <char>)null, x, y, forceFill, forceID, behaviour); if (tiles != null) { tileGrid.Tiles[x - startX, y - startY] = RandomUtil.Random.Choose <MTexture>(tiles.Textures); if (tiles.HasOverlays) { animatedTiles.Set(x - startX, y - startY, RandomUtil.Random.Choose <string>(tiles.OverlapSprites), 1f, 1f); } } } } } return(new Autotiler.Generated() { TileGrid = tileGrid, SpriteOverlay = animatedTiles }); }