Exemplo n.º 1
0
        public Entity CreateFromAsset(object asset)
        {
            Entity entity = null;

            if (asset is Model)
            {
                Model model = asset as Model;

                if (model.Tag is SkinningData)
                {
                    entity = new AnimatedModelEntity(model);
                }
                else
                {
                    entity = new StaticModelEntity(model);
                }
            }
            else if (asset is Texture2D)
            {
                Texture2D texture = asset as Texture2D;
                entity = new Billboard(texture);
            }

            return(entity);
        }
Exemplo n.º 2
0
        public void Save()
        {
            List <XmlEntity> xmlentities = new List <XmlEntity>();
            XmlLevel         xmllevel    = new XmlLevel(name, id, xmlentities);

            for (int i = 0; i < entities.Count; i++)
            {
                Entity entity = entities[i];

                XmlEntity xmlentity = new XmlEntity();
                xmlentity.position = entity.position;
                xmlentity.rotation = entity.rotation;
                xmlentity.size     = entity.size;

                if (entity is StaticModelEntity)
                {
                    StaticModelEntity modelentity = entity as StaticModelEntity;

                    xmlentity.asset = Resources.GetName(modelentity.GetModel());
                    xmlentity.type  = "static_model";
                }

                if (entity is AnimatedModelEntity)
                {
                    AnimatedModelEntity modelentity = entity as AnimatedModelEntity;

                    xmlentity.asset = Resources.GetName(modelentity.GetModel());
                    xmlentity.type  = "animated_model";
                }

                if (entity is WallModelEntity)
                {
                    WallModelEntity wallentity = entity as WallModelEntity;

                    xmlentity.asset = Resources.GetName(wallentity.GetModel());
                    xmlentity.type  = "wall_model";
                }

                if (entity is Billboard)
                {
                    Billboard billboard = entity as Billboard;

                    xmlentity.asset = Resources.GetName(billboard.region.texture);
                    xmlentity.type  = "billboard";
                    xmlentity.color = billboard.color;
                }

                xmlentities.Add(xmlentity);
            }

            XmlHelper.Save(xmllevel);
        }
Exemplo n.º 3
0
        public void Load()
        {
            entities.Clear();

            XmlLevel         xmllevel    = XmlHelper.Load(id);
            List <XmlEntity> xmlentities = xmllevel.entities;

            for (int i = 0; i < xmlentities.Count; i++)
            {
                XmlEntity xmlentity = xmlentities[i];
                Entity    entity    = null;

                if (xmlentity.type == "static_model")
                {
                    Model model = (Model)Resources.GetObject(xmlentity.asset);
                    entity = new StaticModelEntity(model);
                }

                if (xmlentity.type == "animated_model")
                {
                    Model model = (Model)Resources.GetObject(xmlentity.asset);
                    entity = new AnimatedModelEntity(model);
                }

                if (xmlentity.type == "wall_model")
                {
                    Model model = (Model)Resources.GetObject(xmlentity.asset);
                    entity = new WallModelEntity(model);
                }

                if (xmlentity.type == "billboard")
                {
                    Texture2D texture = (Texture2D)Resources.GetObject(xmlentity.asset);
                    entity = new Billboard(texture);
                    ((Billboard)entity).color = xmlentity.color;
                }

                if (entity == null)
                {
                    continue;
                }

                entity.position = xmlentity.position;
                entity.rotation = xmlentity.rotation;
                entity.size     = xmlentity.size;

                Add(entity);
            }
        }