public static LayerRenderer CreateRenderedLayerObject(GameObject mapObject, MapReader.Map mapData, MapReader.Layer layer, int fringeSize = 0) { LayerRenderer renderedLayer = new LayerRenderer(); renderedLayer.goLayer = new GameObject("Layer " + layer.Name); renderedLayer.goLayer.transform.SetParent(mapObject.transform); renderedLayer.tileImages = new TileImage[layer.Data.Length]; for (int i = 0; i < layer.Data.Length; i++) { renderedLayer.tileImages[i] = TileImage.CreateTileImage(renderedLayer.goLayer, mapData, layer, i, fringeSize); } renderedLayer.layer = layer; renderedLayer.width = mapData.Width; renderedLayer.height = mapData.Height; return(renderedLayer); }
public static TileImage CreateTileImage(GameObject parentGameObject, MapReader.Map mapData, MapReader.Layer layer, int tileIndex, int fringeSize = 0) { int tileID = layer.Data[tileIndex]; TileImage image = CreateTileImageOfTileID(parentGameObject, mapData, tileID, fringeSize); MapReader.Tileset tileset = GetTilesetFromTileID(tileID, mapData.Tilesets); image.tileIndex = tileIndex; int yTilePos = (tileIndex / mapData.Width) * tileset.TileHeight; int xTilePos = (tileIndex % mapData.Width) * tileset.TileWidth; Vector3 position = new Vector3(xTilePos, -yTilePos, Game_bottomMapLayerDepth); if (layer.Name.Split(',').Length > 1) { float.TryParse(layer.Name.Split(',')[1], out position.z); //position.z += Game_bottomMapLayerDepth; } //print("position z: " + position.z); image.transform.localPosition = new Vector3(position.x, (position.y), (position.y * Game_depthDivision) + position.z); return(image); }