internal SceneItem InstanciateNewItemOfType(SceneItemType type)
        {
            SceneItem item = null;
            switch (type)
            {
                case SceneItemType.AnimatedSprite:
                    item = new AnimatedSprite();
                    AnimatedSprite animatedSprite = item as AnimatedSprite;
                    animatedSprite.Material = SceneManager.GetEmbeddedTileGridMaterial();
                    AnimationInfo newAnim = new AnimationInfo("Counting");
                    newAnim.AnimationFrames.Add(new AnimationFrame(20, "1"));
                    newAnim.AnimationFrames.Add(new AnimationFrame(20, "2"));
                    newAnim.AnimationFrames.Add(new AnimationFrame(20, "3"));
                    newAnim.AnimationFrames.Add(new AnimationFrame(20, "4"));
                    animatedSprite.AddAnimation(newAnim);
                    animatedSprite.PlayAnimation("Counting");
                    break;
                case SceneItemType.ParticleEffect:
                    item = new ParticleEffect();
                    ParticleEffect effect = item as ParticleEffect;
                    IceCream.SceneItems.ParticlesClasses.ParticleType pType = new IceCream.SceneItems.ParticlesClasses.ParticleType();
                    pType.Material = SceneManager.GetEmbeddedParticleMaterial();                    
                    effect.Emitter.ParticleTypes.Add(pType);
                    effect.Name = "New Particle Effect";
                    effect.Play();
                    break;
                case SceneItemType.PostProcessingAnimation:
                    item = new PostProcessAnimation();
                    item.Layer = 1;
                    break;
                case SceneItemType.Sprite:
                    item = new Sprite();
                    Sprite sprite = item as Sprite;
                    sprite.Name = GetNewSpriteName(); ;
                    sprite.Material = SceneManager.GetEmbeddedParticleMaterial();
                    break;
                case SceneItemType.TextItem:
                    item = new TextItem();
                    TextItem text = item as TextItem;
                    text.Name = GetNewTextItemName();
                    text.Font = SceneManager.GetEmbeddedFont("DefaultFont");
                    break;
                case SceneItemType.TileGrid:
                    item = new TileGrid();
                    TileGrid tileGrid = item as TileGrid;
                    tileGrid.Name = "New Tile Grid";
                    tileGrid.Material = SceneManager.GetEmbeddedTileGridMaterial();

                    tileGrid.TileRows = 4;
                    tileGrid.TileCols = 10;
                    tileGrid.TileSize = new Microsoft.Xna.Framework.Point(32, 32);
                    TileLayer newLayer = new TileLayer(tileGrid.TileCols, tileGrid.TileRows);
                    newLayer.Parent = tileGrid;
                    newLayer.Visible = true;
                    newLayer.Name = "Layer 1";
                    for (int tx = 0; tx < tileGrid.TileCols; tx++)
                    {
                        for (int ty = 0; ty < tileGrid.TileRows; ty++)
                        {
                            newLayer.Tiles[tx][ty].Index = 0;
                        }
                    }
                    tileGrid.TileLayers.Add(newLayer);
                    break;       
                case SceneItemType.CompositeEntity:
                    item = new CompositeEntity();
                    CompositeEntity composite = item as CompositeEntity;
                    break;
                default:
                    item = new SceneItem();
                    break;
            }
            return item;
        }
Exemple #2
0
        private static void WriteParticleEffect(XmlNode itemNode, XmlDocument doc, ParticleEffect particleEffect)
        {

            itemNode.AppendChildIfNotNull(WriteProperty("EditorBackgroundColor", particleEffect, doc));
            WriteIAnimationProperties(doc, itemNode, particleEffect);
            //XmlNode _emitternode=itemNode.AppendChild(_doc.CreateElement("Emitter"));
            try
            {

                XmlSerializerNamespaces ns = new XmlSerializerNamespaces();
                ns.Add("", "");

                MemoryStream ms = new MemoryStream();
                XmlSerializer ser = new XmlSerializer(typeof(Emitter), "");
                XmlWriterSettings sett = new XmlWriterSettings();
                sett.OmitXmlDeclaration = true;
                sett.Indent = true;
                XmlWriter writer = XmlTextWriter.Create(ms, sett);
                ser.Serialize(writer, particleEffect.Emitter, ns);
                ms.Flush();
                ms.Position = 0;

                XmlDocument doc1 = new XmlDocument();
                doc1.Load(ms);

                XmlNode newNode = doc.ImportNode(doc1.SelectSingleNode("Emitter"), true);

                int i = 0;
                XmlNode _node = newNode.SelectSingleNode("ParticleTypes");
                foreach (XmlNode _child in _node.ChildNodes)
                {
                    ParticleType _type = particleEffect.Emitter.ParticleTypes[i];
                    XmlNode _mat = WriteProperty("Material", _type, doc);
                    _mat.Attributes.Append(doc.CreateAttribute("materialSource")).InnerText = GetAssetSource(_type.Material);

                    _child.AppendChildIfNotNull(_mat);
                    //_node.AppendChild(_child);
                    i++;
                }

                itemNode.AppendChildIfNotNull(newNode);
                ms.Close();

            }
            catch (Exception er)
            {
                Console.WriteLine(er.ToString());
                throw er;
            }
        }
Exemple #3
0
        private static SceneItem LoadParticleEffect(XmlNode node, SceneBase scene)
        {
            TraceLogger.TraceInfo("Beginning LoadParticleEffect");

            ParticleEffect _particle = new ParticleEffect();
            LoadBaseSceneItem(node, _particle);

            XmlNode emitterNode = node.SelectSingleNode("Emitter");
            if (emitterNode != null)
            {
                LoadEmitter(emitterNode, _particle, scene);
            }
            SetProperty("EditorBackgroundColor", _particle, node);
            SetIAnimationProperties(node, _particle);

            TraceLogger.TraceInfo("Ending LoadParticleEffect");
            return _particle;
        }
Exemple #4
0
        private static void LoadEmitter(XmlNode emitterNode, ParticleEffect particle, SceneBase scene)
        {
            try
            {
                TraceLogger.TraceInfo("Beginning LoadEmitter");

                particle.Emitter = new IceCream.SceneItems.ParticlesClasses.Emitter();


                XmlDocument doc = new XmlDocument();
                doc.LoadXml(emitterNode.OuterXml);
                XmlReaderSettings sett = new XmlReaderSettings();
                StringReader stringReader = new StringReader(emitterNode.OuterXml);
                XmlTextReader xmlReader = new XmlTextReader(stringReader);

                XmlSerializer ser = new XmlSerializer(typeof(Emitter));
                particle.Emitter = (Emitter)ser.Deserialize(xmlReader);

                XmlNode _types = emitterNode.SelectSingleNode("ParticleTypes");
                if (_types != null)
                {
                    int i = 0;
                    foreach (XmlNode _type in _types.ChildNodes)
                    {
                        ParticleType ptype = particle.Emitter.ParticleTypes[i];
                        XmlNode _matNode = _type.SelectSingleNode("Material");
                        if (_matNode != null)
                        {
                            ptype.Material = GetMaterialAssetFromNode(_matNode, scene);
                            if (ptype.Material == null)
                                throw new Exception("Material Not Found For " + particle.Name);
                        }
                        else
                        {
                            ptype.Material = SceneManager.GetEmbeddedParticleMaterial();
                            TraceLogger.TraceWarning("Particle Effect Node Type Has No Material Set");
                        }
                        i++;
                    }
                }
                TraceLogger.TraceInfo("Ending LoadEmitter");
            }
            catch (Exception err)
            {
                TraceLogger.TraceError("Error Occurred In LoadEmitter" + Environment.NewLine + err.ToString());
                throw err;
            }
        }
 public ParticleEffectControl()
 {
     particleEffect = new ParticleEffect();            
 }