public override void Perform(Tilemap tilemap) { if (tilemap.Size != Point2.Zero) { return; } // Set up the tilemap using default settings. TilemapsSetupUtility.SetupTilemap(tilemap, null); }
public override bool Convert(ConvertOperation convert) { // If we already have a renderer in the result set, consider generating // a tilemap to be not the right course of action. if (convert.Result.OfType <ICmpRenderer>().Any()) { return(false); } List <object> results = new List <object>(); List <Tileset> availData = convert.Perform <Tileset>().ToList(); // Generate objects foreach (Tileset tileset in availData) { if (convert.IsObjectHandled(tileset)) { continue; } // Retrieve previously generated GameObjects and Tilemaps for re-use GameObject gameobj = convert.Result.OfType <GameObject>().FirstOrDefault(); Tilemap tilemap = convert.Result.OfType <Tilemap>().FirstOrDefault(); TilemapRenderer tilemapRenderer = convert.Result.OfType <TilemapRenderer>().FirstOrDefault(); if (tilemap == null && gameobj != null) { tilemap = gameobj.GetComponent <Tilemap>(); } // Create a new Tilemap (and TilemapRenderer) if none did exist before if (tilemap == null) { tilemap = new Tilemap(); TilemapsSetupUtility.SetupTilemap(tilemap, tileset); // Add a renderer for this Tilemap to the result list, if there was none before if (tilemapRenderer == null) { results.Add(new TilemapRenderer()); } } // Configure the Tilemap according to the Tileset we're converting tilemap.Tileset = tileset; // Add the Tilemap to our result set results.Add(tilemap); convert.SuggestResultName(tilemap, tileset.Name); convert.MarkObjectHandled(tileset); } convert.AddResult(results); return(false); }
public override void Do() { if (this.oldData == null) { this.oldData = new Grid <Tile> [this.tilemaps.Length]; for (int i = 0; i < this.tilemaps.Length; i++) { this.oldData[i] = new Grid <Tile>(this.tilemaps[i].BeginUpdateTiles()); this.tilemaps[i].EndUpdateTiles(0, 0, 0, 0); } } for (int i = 0; i < this.tilemaps.Length; i++) { // Determine the tile which should fill the new area Tile fillTile = new Tile(TilemapsSetupUtility.GetDefaultTileIndex( this.tilemaps[i].Tileset.Res, true)); // Determine the up to four regions that we will add int leftAdd = 0; int rightAdd = 0; int topAdd = 0; int bottomAdd = 0; { if (this.origin == Alignment.Right || this.origin == Alignment.TopRight || this.origin == Alignment.BottomRight) { leftAdd = this.newSize.X - this.tilemaps[i].Size.X; } else if ( this.origin == Alignment.Center || this.origin == Alignment.Top || this.origin == Alignment.Bottom) { leftAdd = (this.newSize.X - this.tilemaps[i].Size.X) / 2; } if (this.origin == Alignment.Bottom || this.origin == Alignment.BottomLeft || this.origin == Alignment.BottomRight) { topAdd = this.newSize.Y - this.tilemaps[i].Size.Y; } else if ( this.origin == Alignment.Center || this.origin == Alignment.Left || this.origin == Alignment.Right) { topAdd = (this.newSize.Y - this.tilemaps[i].Size.Y) / 2; } rightAdd = (this.newSize.X - this.tilemaps[i].Size.X) - leftAdd; bottomAdd = (this.newSize.Y - this.tilemaps[i].Size.Y) - topAdd; } // Resize the tilemap this.tilemaps[i].Resize(this.newSize.X, this.newSize.Y, this.origin); // If we have a non-default filling tile, use it if (!object.Equals(fillTile, default(Tile))) { Grid <Tile> data = this.tilemaps[i].BeginUpdateTiles(); if (topAdd > 0) { data.Fill(fillTile, 0, 0, data.Width, topAdd); } if (leftAdd > 0) { data.Fill(fillTile, 0, 0, leftAdd, data.Height); } if (bottomAdd > 0) { data.Fill(fillTile, 0, data.Height - bottomAdd, data.Width, bottomAdd); } if (rightAdd > 0) { data.Fill(fillTile, data.Width - rightAdd, 0, rightAdd, data.Height); } this.tilemaps[i].EndUpdateTiles(0, 0, 0, 0); } } this.OnNotifyPropertyChanged(); }