public static string ColorToString(UColor input) { StringBuilder ret = new StringBuilder(); ret.Append(input.R); ret.Append(" "); ret.Append(input.G); ret.Append(" "); ret.Append(input.B); ret.Append(" "); ret.Append(input.A); return(ret.ToString()); }
public static UColor FromString(string str) { UColor c = new UColor(); string[] parts = str.Split(' '); c.R = float.Parse(parts[0]); c.G = float.Parse(parts[1]); c.B = float.Parse(parts[2]); if (str.Length == 4) { c.A = float.Parse(parts[3]); } else { c.A = 1f; } return(c); }
public ParticleColorFade() { Color = new UColor { R = 1, G = 1, B = 1, A = 1 }; }
public ParticleColorFade(XmlElement e) : this() { color_ = UColor.FromString(e.GetAttribute("color")); time_ = float.Parse(e.GetAttribute("time")); }
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)); } }
public static UColor FromString(string str) { UColor c = new UColor(); string[] parts = str.Split(' '); c.R = float.Parse(parts[0]); c.G = float.Parse(parts[1]); c.B = float.Parse(parts[2]); if (str.Length == 4) c.A = float.Parse(parts[3]); else c.A = 1f; return c; }
public static string ColorToString(UColor input) { StringBuilder ret = new StringBuilder(); ret.Append(input.R); ret.Append(" "); ret.Append(input.G); ret.Append(" "); ret.Append(input.B); ret.Append(" "); ret.Append(input.A); return ret.ToString(); }
public Texture(string fromFile) { //Check for XML file //load xml file //Else create a default xml file Name = fromFile; fileName_ = fromFile; string path = System.IO.Path.ChangeExtension(fromFile, "xml"); try { if (System.IO.File.Exists(path)) { XmlDocument doc = new XmlDocument(); doc.Load(path); XmlElement root = doc.DocumentElement; foreach (XmlElement elem in root.ChildNodes) { if (elem.Name.ToLower().Equals("address")) { string coord = elem.GetAttribute("coord"); string mode = elem.GetAttribute("mode"); TextureAddress addr = TextureAddress.CLAMP; if (mode.Equals("wrap")) { addr = TextureAddress.WRAP; } else if (mode.Equals("repeat")) { addr = TextureAddress.REPEAT; } else if (mode.Equals("clamp")) { addr = TextureAddress.CLAMP; } else if (mode.Equals("border")) { addr = TextureAddress.BORDER; } else if (mode.Equals("mirror")) { addr = TextureAddress.MIRROR; } if (coord.Equals("u")) { this.UAddress = addr; } else if (coord.Equals("v")) { this.VAddress = addr; } else if (coord.Equals("w")) { this.WAddress = addr; } } else if (elem.Name.ToLower().Equals("border")) { if (elem.HasAttribute("color")) { BorderColor = UColor.FromString(elem.GetAttribute("color")); } } else if (elem.Name.ToLower().Equals("filter")) { if (elem.HasAttribute("mode")) { string str = elem.GetAttribute("mode").ToLower(); if (str.Equals("nearest")) { FilteringMode = FilteringMode.NEAREST; } else if (str.Equals("bilinear")) { FilteringMode = FilteringMode.BILINEAR; } else if (str.Equals("trilinear")) { FilteringMode = FilteringMode.TRILINEAR; } else if (str.Equals("anisotropic")) { FilteringMode = FilteringMode.ANISOTROPIC; } else { FilteringMode = FilteringMode.DEFAULT; } } } else if (elem.Name.ToLower().Equals("mipmap")) { if (elem.HasAttribute("enable")) { Mipmapping = elem.GetAttribute("enable").Equals("true"); } } else if (elem.Name.ToLower().Equals("quality")) { if (elem.HasAttribute("low")) { LowQualityMIP = int.Parse(elem.GetAttribute("low")); } if (elem.HasAttribute("medium")) { MedQualityMIP = int.Parse(elem.GetAttribute("medium")); } if (elem.HasAttribute("high")) { HighQualityMIP = int.Parse(elem.GetAttribute("high")); } } else if (elem.Name.ToLower().Equals("srgb")) { if (elem.HasAttribute("enable")) { SRGBEnabled = elem.GetAttribute("enable").Equals("true"); } } } } } catch (Exception ex) { } }
public override void Save() { string path = System.IO.Path.ChangeExtension(fileName_, "xml"); if (DefaultValue.IsDefault(this)) { if (System.IO.File.Exists(path)) { System.IO.File.Delete(path); } return; } XmlDocument doc = new XmlDocument(); XmlElement root = doc.CreateElement("texture"); doc.AppendChild(root); XmlElement addr = writeAddress(doc, "u", UAddress); if (addr != null && !DefaultValue.IsDefault(this, "UAddress")) { root.AppendChild(addr); } addr = writeAddress(doc, "v", VAddress); if (addr != null && !DefaultValue.IsDefault(this, "VAddress")) { root.AppendChild(addr); } addr = writeAddress(doc, "w", WAddress); if (addr != null && !DefaultValue.IsDefault(this, "WAddress")) { root.AppendChild(addr); } if (BorderColor != null && !DefaultValue.IsDefault(this, "BorderColor")) { XmlElement bc = doc.CreateElement("border"); bc.SetAttribute("color", UColor.ColorToString(BorderColor)); root.AppendChild(bc); } XmlElement filt = doc.CreateElement("filter"); filt.SetAttribute("mode", FilteringMode.ToString().ToLower()); if (!DefaultValue.IsDefault(this, "FilteringMode")) { root.AppendChild(filt); } if (Mipmapping && !DefaultValue.IsDefault(this, "Mipmapping")) { XmlElement elem = doc.CreateElement("mipmap"); elem.SetAttribute("enabled", "true"); root.AppendChild(elem); } if (SRGBEnabled && !DefaultValue.IsDefault(this, "SRGBEnabled")) { XmlElement elem = doc.CreateElement("srgb"); elem.SetAttribute("enabled", "true"); root.AppendChild(elem); } XmlWriterSettings xws = new XmlWriterSettings { OmitXmlDeclaration = true, Indent = true }; using (XmlWriter xw = XmlWriter.Create(System.IO.Path.ChangeExtension(Name, "xml"), xws)) doc.Save(xw); }