コード例 #1
0
        public object Deserialize(DeSerializerProxy DeSerializerProxy)
        {
            GraphicFactory GraphicFactory = (GraphicFactory)DeSerializerProxy.Context;
            ObjectMock     ObjectMock     = new ObjectMock(GraphicFactory, DeSerializerProxy.DeSerialize <String>("modelname"), DeSerializerProxy.DeSerialize <Vector3>("position"),
                                                           DeSerializerProxy.DeSerialize <Matrix>("ori"), DeSerializerProxy.DeSerialize <Vector3>("scale"));

            return(ObjectMock);
        }
コード例 #2
0
        protected override void LoadContent(GraphicInfo GraphicInfo, GraphicFactory factory, IContentManager contentManager)
        {
            base.LoadContent(GraphicInfo, factory, contentManager);


            ///Serializing a basic type
            SerializatorWrapper SerializatorWrapper = new SerializatorWrapper();

            SerializatorWrapper.Serialize(new Vector3(10, 20, 30), "vetor.xml");

            ///loading it
            Vector3 vec = (Vector3)SerializatorWrapper.Desserialize <Vector3>("vetor.xml", null);

            Debug.Assert(vec.X == 10);
            Debug.Assert(vec.Y == 20);
            Debug.Assert(vec.Z == 30);

            ///same to PloobsMockType
            ObjectMock ObjectMock = new ObjectMock(GraphicFactory, "Model/cenario", Vector3.Zero, Matrix.Identity, Vector3.One);

            SerializatorWrapper.Serialize(ObjectMock, "cena.xml");

            ObjectMock mloaded = (ObjectMock)SerializatorWrapper.Desserialize <ObjectMock>("cena.xml", GraphicFactory);

            this.World.AddObject(mloaded);


            IObject obj;

            {
                SimpleModel simpleModel = new SimpleModel(factory, "Model//ball");
                simpleModel.SetTexture(factory.CreateTexture2DColor(1, 1, Color.Green), TextureType.DIFFUSE);
                SphereObject tmesh = new SphereObject(new Vector3(100, 200, 10), 1, 5, 5, MaterialDescription.DefaultBepuMaterial());
                tmesh.isMotionLess = false;
                ForwardXNABasicShader shader    = new ForwardXNABasicShader(ForwardXNABasicShaderDescription.Default());
                ForwardMaterial       fmaterial = new ForwardMaterial(shader);
                obj = new IObject(fmaterial, simpleModel, tmesh);
                this.World.AddObject(obj);
            }


            this.BindInput(new SimpleConcreteKeyboardInputPlayable(StateKey.PRESS, Keys.Space,
                                                                   (a) =>
            {
                this.World.RemoveObject(obj);
                DynamicObjectSaver DynamicObjectSaver = new DynamicObjectSaver(obj.Modelo.Name, obj.PhysicObject.Position, obj.PhysicObject.Rotation, obj.PhysicObject.Scale, obj.PhysicObject.Velocity, obj.PhysicObject.AngularVelocity);
                SerializatorWrapper.Serialize(DynamicObjectSaver, "dyn.xml");

                DynamicObjectSaver dloaded = (DynamicObjectSaver)SerializatorWrapper.Desserialize <DynamicObjectSaver>("dyn.xml");
                SimpleModel simpleModel    = new SimpleModel(factory, dloaded.modelName);
                simpleModel.SetTexture(factory.CreateTexture2DColor(1, 1, Color.Green), TextureType.DIFFUSE);
                SphereObject tmesh           = new SphereObject(dloaded.position, 1, 10, dloaded.scale.X, MaterialDescription.DefaultBepuMaterial());
                tmesh.Rotation               = dloaded.orientation;
                tmesh.Velocity               = dloaded.LinearVelocity;
                tmesh.AngularVelocity        = dloaded.AngularVelocity;
                ForwardXNABasicShader shader = new ForwardXNABasicShader(ForwardXNABasicShaderDescription.Default());
                ForwardMaterial fmaterial    = new ForwardMaterial(shader);
                obj = new IObject(fmaterial, simpleModel, tmesh);
                this.World.AddObject(obj);
                saved++;
            }
                                                                   ));

            this.World.CameraManager.AddCamera(new CameraFirstPerson(GraphicInfo));
        }