private void deserializeObject(Type type, TWXmlNode node, object obj) { foreach (var fieldInfo in type.GetFields()) { var childNode = node.FindChildNode(fieldInfo.Name); if (childNode == null) { continue; } fieldInfo.SetValue(obj, deserializeElement(childNode, fieldInfo.FieldType)); } foreach (var propertyInfo in type.GetProperties()) { if (propertyInfo.GetGetMethod() == null || propertyInfo.GetSetMethod() == null) { continue; } if (propertyInfo.GetIndexParameters().Length != 0) { continue; } var childNode = node.FindChildNode(propertyInfo.Name); if (childNode == null) { continue; } propertyInfo.SetValue(obj, deserializeElement(childNode, propertyInfo.PropertyType), null); } }
public WorldObject DeserializeWorldObject(World world, TWXmlNode node) { var obj = world.CreateNewWorldObject(game, worldObjectTypeFactory.GetWorldObjectType(XMLSerializer.ReadGuid(node.FindChildNode("Type"))), renderer); obj.Position = XMLSerializer.ReadVector3(node.FindChildNode("Position")); obj.Rotation = XMLSerializer.ReadQuaternion(node.FindChildNode("Rotation")); return(obj); }
public WorldObjectType DeserializeWorldObjectType(TWXmlNode node) { var type = new WorldObjectType(meshFactory.GetMesh(XMLSerializer.ReadGuid(node.FindChildNode("Mesh"))), XMLSerializer.ReadGuid(node.FindChildNode("Guid")), builder); type.TileData = diskTileDataFactory.GetTileData(XMLSerializer.ReadGuid(node.FindChildNode("TileData"))); if (type.TileData == null) { throw new InvalidOperationException("TileData For WorldObjectType not found!!"); } return(type); }
public void Load(DirectoryInfo dir) { TWXmlNode root = TWXmlNode.GetRootNodeFromFile(dir.FullName + "\\World.xml"); var entitiesNode = root.FindChildNode("Entities"); var entityNodes = entitiesNode.GetChildNodes(); for (int i = 0; i < entityNodes.Length; i++) { var entityNode = entityNodes[i]; var type = entityNode.GetAttribute("Type"); var relativePath = entityNode.GetAttribute("RelativePath"); var serializer = new XmlSerializer(Type.GetType(type)); var fi = new FileInfo(dir.FullName + "\\" + relativePath); var ent = loadEntity(fi, Type.GetType(type)); entities.Add(ent); } using (var fs = new FileStream(dir.FullName + "\\World.xml", FileMode.OpenOrCreate)) { root.Document.Save(fs); } }
public void Load(TWXmlNode assetNode) { UpAxis = UpAxisType.None; UnitName = "Unknown"; UnitInMeters = 1; string up_axis = assetNode.ReadChildNodeValue("up_axis", ""); if (up_axis == "Z_UP") { UpAxis = UpAxisType.Z_UP; } TWXmlNode unitNode = assetNode.FindChildNode("unit"); UnitName = unitNode.GetAttribute("inch"); UnitInMeters = float.Parse(unitNode.GetAttribute("meter")); }