static CCTMXLayer ParseLayer(XmlNode nodeData, int cols, int rows, Dictionary <int, string> gidToFiles, Dictionary <int, Dictionary <string, string> > gidToTileProperties) { XmlNode data = nodeData.SelectSingleNode("data"); string name = nodeData.Attributes["name"].InnerText; string encoding = data.Attributes["encoding"].InnerText; NSUtils.Assert(encoding == "csv", "cocos2d:CCTMXMapParser: Unsupported encoding {0} found. Only csv is supported now.", encoding); string csvData = data.InnerText; CCTMXTiledLayer layer = new CCTMXTiledLayer(); layer.name = name; layer.visiable = nodeData.Attributes["visible"] != null && nodeData.Attributes["visible"].InnerText == "0"; layer.tiles = new CCTMXTile[rows][]; for (int row = 0; row < rows; row++) { layer.tiles[row] = new CCTMXTile[cols]; } string[] layerData = csvData.Split(','); int totalTiles = cols * rows; for (int i = 0; i < totalTiles; i++) { int col = i % cols; int row = Mathf.FloorToInt(i / cols); int tileId = int.Parse(layerData[i].ToString().Trim()); if (tileId > 0) { CCTMXTile tile = new CCTMXTile(); tile.gid = tileId; tile.col = col; tile.row = row; try{ tile.file = gidToFiles[tile.gid]; }catch { throw new UnityEngine.UnityException(string.Format("cocos2d: CCTMXMapParser: gid [{0}] not found", tile.gid)); } Dictionary <string, string> tileProperties = null; if (!gidToTileProperties.TryGetValue(tile.gid, out tileProperties)) { tileProperties = null; } tile.sharedProperties = tileProperties; layer.tiles[row][col] = tile; } } XmlNode propertiesNode = nodeData.SelectSingleNode("properties"); if (propertiesNode != null) { layer.properties = new Dictionary <string, string>(); ParseProperties(propertiesNode, layer.properties); } return(layer); }
static CCTMXLayer ParseLayer(XmlNode nodeData, int cols, int rows, Dictionary<int, string> gidToFiles, Dictionary<int, Dictionary<string, string>> gidToTileProperties){ XmlNode data = nodeData.SelectSingleNode("data"); string name = nodeData.Attributes["name"].InnerText; string encoding = data.Attributes["encoding"].InnerText; NSUtils.Assert (encoding=="csv", "cocos2d:CCTMXMapParser: Unsupported encoding {0} found. Only csv is supported now.", encoding); string csvData = data.InnerText; CCTMXTiledLayer layer = new CCTMXTiledLayer(); layer.name = name; layer.visiable = nodeData.Attributes["visible"] != null && nodeData.Attributes["visible"].InnerText == "0"; layer.tiles = new CCTMXTile[rows][]; for (int row=0; row<rows; row++) { layer.tiles[row] = new CCTMXTile[cols]; } string[] layerData = csvData.Split(','); int totalTiles = cols * rows; for (int i = 0; i < totalTiles; i++) { int col = i % cols; int row = Mathf.FloorToInt(i / cols); int tileId = int.Parse(layerData[i].ToString().Trim()); if(tileId>0){ CCTMXTile tile = new CCTMXTile(); tile.gid = tileId; tile.col = col; tile.row = row; try{ tile.file = gidToFiles[tile.gid]; }catch{ throw new UnityEngine.UnityException(string.Format("cocos2d: CCTMXMapParser: gid [{0}] not found", tile.gid)); } Dictionary<string, string> tileProperties = null; if(!gidToTileProperties.TryGetValue(tile.gid, out tileProperties)){ tileProperties = null; } tile.sharedProperties = tileProperties; layer.tiles[row][col] = tile; } } XmlNode propertiesNode = nodeData.SelectSingleNode("properties"); if(propertiesNode!=null){ layer.properties = new Dictionary<string, string>(); ParseProperties(propertiesNode, layer.properties); } return layer; }