/// <summary> /// Query if this type can be placed in this position. /// </summary> /// <param name="type">Type of the tile entity</param> /// <param name="TargetPosition">Target tile position</param> /// <returns>If the placement can take place</returns> public bool QueryPlaceByType(Type type, Vector2Int TargetPosition) { //Try to get the TileEntityMeta attribute TileEntityMetaAttribute meta = Attribute.GetCustomAttribute(type, typeof(TileEntityMetaAttribute)) as TileEntityMetaAttribute; if (meta != null) { bool[,] requiredTiles = meta.RequiredTiles; for (int x = 0; x < 3; x++) { for (int y = 0; y < 3; y++) { //If this tile offset should be occupied. if (requiredTiles[y, x]) { Vector2Int checkPosOffset = new Vector2Int(x - 1, y - 1); //If this tile is occupied, return false. GridTile tile = GetTile(TargetPosition + checkPosOffset); if (tile == null || tile.Occipied) { return(false); } } } } } //We can place as no checked positions were occupied. return(true); }
public override void OnEntityProduced(GridSystem grid) { base.OnEntityProduced(grid); //Occupy the adjacent tiles depending on our size //Get the layout from the enum. OccupyTiles(TileEntityMetaAttribute.GetTileLayout(MultiTileSize.x2)); }
public override void OnDestroy() { UnOccupyTiles(TileEntityMetaAttribute.GetTileLayout(MultiTileSize.x2)); base.OnDestroy(); }