private void _serializeTsx(tileset _tileSet, string strFileName) { XmlSerializer serializer = new XmlSerializer(_tileSet.GetType()); StreamWriter writer = new StreamWriter("test.tsx"); serializer.Serialize(writer.BaseStream, _tileSet); writer.Close(); }
public void TsxSerializeData() { DeserializeSpriteYaml(); m_tileSet = new tileset(); int nMaxRow = 0; int nMaxColumn = 0; foreach (CustomYamlClass.Sprite _spr in m_rootDataTsx.TextureImporter.spriteSheet.sprites) { m_tileSet.tilewidth = (byte)_spr.rect.width; m_tileSet.tileheight = (byte)_spr.rect.height; int nCol = _spr.rect.x / m_tileSet.tilewidth; if (nMaxColumn < nCol) { nMaxColumn = nCol; } int nRow = _spr.rect.y / m_tileSet.tileheight; if (nMaxRow < nRow) { nMaxRow = nRow; } } nMaxColumn++; nMaxRow++; m_tileSet.columns = (byte)nMaxColumn; m_tileSet.tilecount = (byte)(nMaxColumn * nMaxRow); m_tileSet.version = 1.2m; m_tileSet.tiledversion = "1.3.1"; m_tileSet.name = "baba"; tilesetImage _img = new tilesetImage(); _img.height = (byte)(nMaxColumn * m_tileSet.tileheight); _img.width = (byte)(nMaxRow * m_tileSet.tilewidth); _img.source = "Assets/Resources/Sprites/SmallPalette.png"; m_tileSet.image = _img; _serializeTsx(m_tileSet, "test.tsx"); XmlSerializer serializer = new XmlSerializer(m_tileSet.GetType()); StreamWriter writer = new StreamWriter("test.tsx"); serializer.Serialize(writer.BaseStream, m_tileSet); writer.Close(); }