コード例 #1
0
        public object Deserialize(XElement root, Deserializer deserializer)
        {
            //Проверяем, был ли уже сериализован данный объект
            object crObject = deserializer.GetCRObject(root);

            if (crObject != null)
            {
                return(crObject);
            }

            //Десериализуем гравитацию и создаём новый world
            Vector2 gravity = (Vector2)DefaultConverters.StringToVector2(root.Attribute("Gravity").Value);
            World   world   = new World(gravity);

            deserializer.DeserializeMetadata(root, world);
            //Добавляем world в список уже десериализованных объектов
            deserializer.AddToCRList(root, world);

            //Десериализуем bodies
            var bodiesElement = root.Element("Bodies");
            var bodyElements  = bodiesElement.Elements("Body");

            foreach (XElement bodyElement in bodyElements)
            {
                Body body = (Body)deserializer.DeserializeObject(bodyElement);
                world.BodyList.Add(body);
            }

            //Десериализуем joint'ы
            var jointsElement = root.Element("Joints");
            var jointElements = jointsElement.Elements("Joint");

            foreach (XElement jointElement in jointElements)
            {
                Joint joint = (Joint)deserializer.DeserializeObject(jointElement);
                world.AddJoint(joint);
            }

            return(world);
        }
コード例 #2
0
        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);
        }