Exemplo n.º 1
0
        public ParticleEffect(string fileName)
        {
            Name       = fileName;
            colorFade_ = new ObservableCollection <ParticleColorFade>();
            texAnim_   = new ObservableCollection <ParticleTexAnim>();
            type_      = EmitterType.Box;

            string path = System.IO.Path.ChangeExtension(fileName, "xml");

            if (System.IO.File.Exists(path))
            {
                XmlDocument doc = new XmlDocument();
                doc.Load(path);

                foreach (XmlElement mat in doc.DocumentElement.GetElementsByTagName("material"))
                {
                    Material = mat.GetAttribute("name");
                }
                foreach (XmlElement num in doc.DocumentElement.GetElementsByTagName("numparticles"))
                {
                    foreach (XmlElement u in doc.DocumentElement.GetElementsByTagName("updateinvisible"))
                    {
                        UpdateInvisible = u.GetAttribute("enable").Equals("true");
                    }
                }
                foreach (XmlElement rel in doc.DocumentElement.GetElementsByTagName("relative"))
                {
                    Relative = rel.GetAttribute("enable").Equals("true");
                }
                foreach (XmlElement s in doc.DocumentElement.GetElementsByTagName("scaled"))
                {
                    Scaled = s.GetAttribute("enable").Equals("true");
                }
                foreach (XmlElement s in doc.DocumentElement.GetElementsByTagName("sorted"))
                {
                    Sorted = s.GetAttribute("enable").Equals("true");
                }
                foreach (XmlElement s in doc.DocumentElement.GetElementsByTagName("animlodbias"))
                {
                    AnimLodBias = float.Parse(s.GetAttribute("value"));
                }
                foreach (XmlElement t in doc.DocumentElement.GetElementsByTagName("emittertype"))
                {
                    foreach (EmitterType type in Enum.GetValues(typeof(EmitterType)))
                    {
                        if (type.ToString().ToLower().Equals(t.GetAttribute("value")))
                        {
                            Type = type;
                            break;
                        }
                    }
                }
                foreach (XmlElement s in doc.DocumentElement.GetElementsByTagName("emittersize"))
                {
                    EmitterSize = Vector3.FromString(s.GetAttribute("value"));
                }
                foreach (XmlElement s in doc.DocumentElement.GetElementsByTagName("emitterradius"))
                {
                    EmitterRadius = float.Parse(s.GetAttribute("value"));
                }
                foreach (XmlElement d in doc.DocumentElement.GetElementsByTagName("direction"))
                {
                    DirectionMax = Vector3.FromString(d.GetAttribute("max"));
                    DirectionMin = Vector3.FromString(d.GetAttribute("min"));
                }
                foreach (XmlElement s in doc.DocumentElement.GetElementsByTagName("constantforce"))
                {
                    ConstantForce = Vector3.FromString(s.GetAttribute("value"));
                }
                foreach (XmlElement s in doc.DocumentElement.GetElementsByTagName("dampingforce"))
                {
                    DampingForce = float.Parse(s.GetAttribute("value"));
                }
                foreach (XmlElement s in doc.DocumentElement.GetElementsByTagName("activetime"))
                {
                    ActiveTime = float.Parse(s.GetAttribute("value"));
                }
                foreach (XmlElement s in doc.DocumentElement.GetElementsByTagName("inactivetime"))
                {
                    InActiveTime = float.Parse(s.GetAttribute("value"));
                }
                foreach (XmlElement s in doc.DocumentElement.GetElementsByTagName("interval"))
                {
                    Interval = MinMax.FromElement(s);
                }
                foreach (XmlElement s in doc.DocumentElement.GetElementsByTagName("emissionrate"))
                {
                    EmissionRate = MinMax.FromElement(s);
                }
                foreach (XmlElement s in doc.DocumentElement.GetElementsByTagName("particlesize"))
                {
                    if (s.HasAttribute("min"))
                    {
                        MinSize = Vector2.FromString(s.GetAttribute("min"));
                    }
                    if (s.HasAttribute("max"))
                    {
                        MaxSize = Vector2.FromString(s.GetAttribute("max"));
                    }
                    if (s.HasAttribute("value"))
                    {
                        MinSize = Vector2.FromString(s.GetAttribute("value"));
                        MaxSize = Vector2.FromString(s.GetAttribute("value"));
                    }
                }
                foreach (XmlElement s in doc.DocumentElement.GetElementsByTagName("timetolive"))
                {
                    TimeToLive = MinMax.FromElement(s);
                }
                foreach (XmlElement s in doc.DocumentElement.GetElementsByTagName("velocity"))
                {
                    Velocity = MinMax.FromElement(s);
                }
                foreach (XmlElement s in doc.DocumentElement.GetElementsByTagName("rotation"))
                {
                    Rotation = MinMax.FromElement(s);
                }
                foreach (XmlElement s in doc.DocumentElement.GetElementsByTagName("rotationspeed"))
                {
                    RotationSpeed = MinMax.FromElement(s);
                }
                foreach (XmlElement s in doc.DocumentElement.GetElementsByTagName("sizedelta"))
                {
                    Vector2 sd = new Vector2();
                    if (s.HasAttribute("add"))
                    {
                        sd.X = float.Parse(s.GetAttribute("add"));
                    }
                    if (s.HasAttribute("mul"))
                    {
                        sd.Y = float.Parse(s.GetAttribute("mul"));
                    }
                    SizeDelta = sd;
                }

                foreach (XmlElement s in doc.DocumentElement.GetElementsByTagName("colorfade"))
                {
                    ColorFade.Add(new ParticleColorFade(s));
                }
                foreach (XmlElement s in doc.DocumentElement.GetElementsByTagName("texanim"))
                {
                    TextureAnim.Add(new ParticleTexAnim(s));
                }
            }
            else
            {
                // Add the initial color fade
                // ColorFade.Add(new ParticleColorFade() { Color = new UColor(1, 1, 1, 1), Time = 0 });
            }
        }