示例#1
0
 public static MinMax FromElement(XmlElement e)
 {
     MinMax ret = new MinMax();
     if (e.HasAttribute("value")) {
         ret.Min = ret.Max = float.Parse(e.GetAttribute("value"));
     } else {
         ret.Min = float.Parse(e.GetAttribute("min"));
         ret.Max = float.Parse(e.GetAttribute("max"));
     }
     return ret;
 }
示例#2
0
        public ParticleEffect(string fileName)
        {
            Name = fileName;
            colorFade_ = new ObservableCollection<ParticleColorFade>();
            texAnim_ = new ObservableCollection<ParticleTexAnim>();
            type_ = EmitterType.Box;
            emissionRate_ = new MinMax();
            directionMax_ = new Vector3();
            directionMax_ = new Vector3();
            emitterSize_ = new Vector3();
            constantForce_ = new Vector3();
            interval_ = new MinMax();
            minSize_ = new Vector2();
            maxSize_ = new Vector2();
            timeToLive_ = new MinMax();
            velocity_ = new MinMax();
            rotation_ = new MinMax();
            rotation_ = new MinMax();
            sizeDelta_ = new Vector2() { X = 0, Y = 1 };
            color_ = new UColor { A = 1, B = 1, G = 1, R = 1 };

            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("color"))
                    Color = UColor.FromString(s.GetAttribute("color"));

                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));
            }
        }
示例#3
0
 public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
 {
     string[] parts = value.ToString().Replace("  ", " ").Replace("  ", " ").Split(' ');
     if (parts.Length == 2) {
         MinMax v = new MinMax();
         v.Min = float.Parse(parts[0]);
         v.Max = float.Parse(parts[1]);
         return v;
     } else if (parts.Length == 1) {
         MinMax v = new MinMax();
         v.Min = v.Max = float.Parse(parts[0]);
         return v;
     } else {
         return null;
     }
 }