public object Deserialize(XElement root, Deserializer deserializer) { object crObject = deserializer.GetCRObject(root); if (crObject != null) { return(crObject); } Body body = (Body)deserializer.DeserializeObject(root.Element("Body")); Shape shape = (Shape)deserializer.DeserializeObject(root.Element("Shape")); Fixture fixture = new Fixture(body, shape); deserializer.DeserializeMetadata(root, fixture); deserializer.AddToCRList(root, fixture); fixture.CollisionCategories = (Category)DefaultConverters.StringToInt(root.Attribute("CategoryBits").Value); fixture.CollidesWith = (Category)DefaultConverters.StringToInt(root.Attribute("MaskBits").Value); fixture.CollisionGroup = (short)DefaultConverters.StringToShort(root.Attribute("GroupIndex").Value); fixture.Friction = (float)DefaultConverters.StringToFloat(root.Attribute("Friction").Value); fixture.IsSensor = (bool)DefaultConverters.StringToBool(root.Attribute("IsSensor").Value); fixture.Restitution = (float)DefaultConverters.StringToFloat(root.Attribute("Restitution").Value); return(fixture); }
public object Deserialize(XElement root, Deserializer deserializer) { object crObject = deserializer.GetCRObject(root); if (crObject != null) { return(crObject); } World world = (World)deserializer.DeserializeObject(root.Element("World")); Body body = new Body(world); deserializer.DeserializeMetadata(root, body); deserializer.AddToCRList(root, body); body.BodyType = (BodyType)DefaultConverters.StringToInt(root.Attribute("BodyType").Value); body.Enabled = (bool)DefaultConverters.StringToBool(root.Attribute("Active").Value); body.SleepingAllowed = (bool)DefaultConverters.StringToBool(root.Attribute("AllowSleep").Value); body.Rotation = (float)DefaultConverters.StringToFloat(root.Attribute("Angle").Value); body.AngularDamping = (float)DefaultConverters.StringToFloat(root.Attribute("AngularDamping").Value); body.AngularVelocity = (float)DefaultConverters.StringToFloat(root.Attribute("AngularVelocity").Value); body.Awake = (bool)DefaultConverters.StringToBool(root.Attribute("Awake").Value); body.IsBullet = (bool)DefaultConverters.StringToBool(root.Attribute("Bullet").Value); body.FixedRotation = (bool)DefaultConverters.StringToBool(root.Attribute("FixedRotation").Value); body.LinearDamping = (float)DefaultConverters.StringToFloat(root.Attribute("LinearDamping").Value); body.LinearVelocity = (Vector2)DefaultConverters.StringToVector2(root.Attribute("LinearVelocity").Value); body.Position = (Vector2)DefaultConverters.StringToVector2(root.Attribute("Position").Value); var fixturesElement = root.Element("Fixtures"); var fixtureElements = fixturesElement.Elements("Fixture"); foreach (XElement fixtureElement in fixtureElements) { Fixture fixture = (Fixture)deserializer.DeserializeObject(fixtureElement); body.FixtureList.Add(fixture); } return(body); }