public XElement Serialize(string name, object rootObject, Serializer serializer) { XElement root = new XElement(name); //Обрабатываем кольцевые ссылки if (serializer.CheckCircularReferences(root, rootObject)) { return(root); } //Сериализуем метаданные Serializer.SerializeMetadata(root, rootObject); //Сериализуем имя типа Serializer.SerializeTypeName(root, typeof(Fixture)); Fixture fixture = (Fixture)rootObject; root.Add(serializer.SerializeObject("Shape", fixture.Shape)); root.Add( new XAttribute("CategoryBits", DefaultConverters.IntToString((int)fixture.CollisionCategories)), new XAttribute("MaskBits", DefaultConverters.IntToString((int)fixture.CollidesWith)), new XAttribute("GroupIndex", DefaultConverters.ShortToString(fixture.CollisionGroup)), new XAttribute("Friction", DefaultConverters.FloatToString(fixture.Friction)), new XAttribute("IsSensor", DefaultConverters.BoolToString(fixture.IsSensor)), new XAttribute("Restitution", DefaultConverters.FloatToString(fixture.Restitution)), serializer.SerializeObject("Body", fixture.Body)); return(root); }
public XElement Serialize(string name, object rootObject, Serializer serializer) { XElement root = new XElement(name); //Обрабатываем кольцевые ссылки if (serializer.CheckCircularReferences(root, rootObject)) { return(root); } //Сериализуем метаданные Serializer.SerializeMetadata(root, rootObject); //Сериализуем имя типа Serializer.SerializeTypeName(root, typeof(Body)); Body body = (Body)rootObject; root.Add( new XAttribute("BodyType", DefaultConverters.IntToString((int)body.BodyType)), new XAttribute("Active", DefaultConverters.BoolToString(body.Enabled)), new XAttribute("AllowSleep", DefaultConverters.BoolToString(body.SleepingAllowed)), new XAttribute("Angle", DefaultConverters.FloatToString(body.Rotation)), new XAttribute("AngularDamping", DefaultConverters.FloatToString(body.AngularDamping)), new XAttribute("AngularVelocity", DefaultConverters.FloatToString(body.AngularVelocity)), new XAttribute("Awake", DefaultConverters.BoolToString(body.Awake)), new XAttribute("Bullet", DefaultConverters.BoolToString(body.IsBullet)), new XAttribute("FixedRotation", DefaultConverters.BoolToString(body.FixedRotation)), new XAttribute("LinearDamping", DefaultConverters.FloatToString(body.LinearDamping)), new XAttribute("LinearVelocity", DefaultConverters.Vector2ToString(body.LinearVelocity)), new XAttribute("Position", DefaultConverters.Vector2ToString(body.Position)), serializer.SerializeObject("World", SerializerHelpers.GetFieldValue(body, "World"))); XElement fixtures = new XElement("Fixtures"); for (int i = 0; i < body.FixtureList.Count; i++) { fixtures.Add(serializer.SerializeObject("Fixture", body.FixtureList[i])); } root.Add(fixtures); return(root); }