示例#1
0
        public override bool Update(System.Xml.XmlDocument document)
        {
            List <System.Xml.XmlNode> nodes = new List <System.Xml.XmlNode>();

            Action <System.Xml.XmlNode> collectNodes = null;

            collectNodes = (node) =>
            {
                if (node.Name == "Node")
                {
                    nodes.Add(node);
                }

                for (int i = 0; i < node.ChildNodes.Count; i++)
                {
                    collectNodes(node.ChildNodes[i]);
                }
            };

            collectNodes((XmlNode)document);

            foreach (var node in nodes)
            {
                var rcv1 = node["AdvancedRendererCommonValuesValues"];
                if (rcv1 != null)
                {
                    var enableAlphaTexture = rcv1["EnableAlphaTexture"];
                    if (enableAlphaTexture != null)
                    {
                        var alphaTextureParam = rcv1["AlphaTextureParam"] as XmlNode;
                        alphaTextureParam?.PrependChild(document.CreateTextElement("Enabled", enableAlphaTexture.InnerText));
                    }

                    var enableUVDistortion = rcv1["EnableUVDistortion"];
                    if (enableUVDistortion != null)
                    {
                        var uvDistortionParam = rcv1["UVDistortionParam"] as XmlNode;
                        uvDistortionParam?.PrependChild(document.CreateTextElement("Enabled", enableUVDistortion.InnerText));
                    }

                    var alphaCutoffParam = rcv1["AlphaCutoffParam"] as XmlNode;
                    if (alphaCutoffParam != null)
                    {
                        var  typeNode          = alphaCutoffParam["Type"];
                        var  fixedNode         = alphaCutoffParam["Fixed"];
                        bool enableAlphaCutoff =
                            (typeNode != null && int.Parse(typeNode.InnerText) != 0) ||
                            (fixedNode != null && float.Parse(fixedNode["Threshold"].InnerText) != 0.0f);
                        alphaCutoffParam.PrependChild(document.CreateTextElement("Enabled", enableAlphaCutoff.ToString()));
                    }

                    var enableFalloff = rcv1["EnableFalloff"];
                    if (enableFalloff != null)
                    {
                        var falloffParam = rcv1["FalloffParam"] as XmlNode;
                        falloffParam.PrependChild(document.CreateTextElement("Enabled", enableFalloff.InnerText));
                    }

                    var softParticleDistance           = rcv1["SoftParticleDistance"];
                    var softParticleDistanceNear       = rcv1["SoftParticleDistanceNear"];
                    var softParticleDistanceNearOffset = rcv1["SoftParticleDistanceNearOffset"];

                    if (softParticleDistance != null || softParticleDistanceNear != null || softParticleDistanceNearOffset != null)
                    {
                        var softParticleParams = document.CreateElement("SoftParticleParams");

                        if (softParticleDistance != null)
                        {
                            softParticleParams.AppendChild(document.CreateTextElement("Enabled", (softParticleDistance.GetTextAsFloat() != 0.0f).ToString()));
                            softParticleParams.AppendChild(document.CreateTextElement("Distance", softParticleDistance.InnerText));
                        }
                        if (softParticleDistanceNear != null)
                        {
                            softParticleParams.AppendChild(document.CreateTextElement("DistanceNear", softParticleDistanceNear.InnerText));
                        }
                        if (softParticleDistanceNearOffset != null)
                        {
                            softParticleParams.AppendChild(document.CreateTextElement("DistanceNearOffset", softParticleDistanceNearOffset.InnerText));
                        }

                        rcv1.AppendChild(softParticleParams);
                    }
                }

                var rcv2 = node["AdvancedRendererCommonValues2Values"];
                if (rcv2 != null)
                {
                    node.RemoveChild(rcv2);

                    if (rcv1 == null)
                    {
                        rcv1 = document.CreateElement("AdvancedRendererCommonValuesValues");
                        node.AppendChild(rcv1);
                    }

                    var blendTextureParams = rcv2["BlendTextureParams"];
                    var enableBlendTexture = rcv2["EnableBlendTexture"];

                    if (enableBlendTexture != null && blendTextureParams != null)
                    {
                        rcv2.RemoveChild(blendTextureParams);
                        rcv2.RemoveChild(enableBlendTexture);
                        blendTextureParams.AppendChild(document.CreateTextElement("Enabled", enableBlendTexture.InnerText));
                        rcv1.AppendChild(blendTextureParams);
                    }
                }
            }

            return(true);
        }
示例#2
0
文件: IO.cs 项目: kou-yeung/Effekseer
        public static XmlElement SaveToElement(XmlDocument doc, string element_name, Value.FCurveColorRGBA value, bool isClip)
        {
            var e = doc.CreateElement(element_name);
            var keys = doc.CreateElement("Keys");
            var r = doc.CreateElement("R");
            var g = doc.CreateElement("G");
            var b = doc.CreateElement("B");
            var a = doc.CreateElement("A");

            int index = 0;

            Action<Value.FCurve<byte>, XmlElement> setValues = (v, xml) =>
            {
                index = 0;

                var st = SaveToElement(doc, "StartType", v.StartType, isClip);
                var et = SaveToElement(doc, "EndType", v.EndType, isClip);
                var omax = SaveToElement(doc, "OffsetMax", v.OffsetMax, isClip);
                var omin = SaveToElement(doc, "OffsetMin", v.OffsetMin, isClip);
                var s = SaveToElement(doc, "Sampling", v.Sampling, isClip);

                if (st != null) xml.AppendChild(st);
                if (et != null) xml.AppendChild(et);
                if (omax != null) xml.AppendChild(omax);
                if (omin != null) xml.AppendChild(omin);
                if (s != null) xml.AppendChild(s);

                foreach (var k_ in v.Keys)
                {
                    var k = doc.CreateElement("Key" + index.ToString());
                    k.AppendChild(doc.CreateTextElement("Frame", k_.Frame.ToString()));
                    k.AppendChild(doc.CreateTextElement("Value", k_.ValueAsFloat.ToString()));
                    k.AppendChild(doc.CreateTextElement("LeftX", k_.LeftX.ToString()));
                    k.AppendChild(doc.CreateTextElement("LeftY", k_.LeftY.ToString()));
                    k.AppendChild(doc.CreateTextElement("RightX", k_.RightX.ToString()));
                    k.AppendChild(doc.CreateTextElement("RightY", k_.RightY.ToString()));

                    k.AppendChild(doc.CreateTextElement("InterpolationType", k_.InterpolationType.GetValueAsInt()));

                    xml.AppendChild(k);
                    index++;
                }
            };

            setValues(value.R, r);
            setValues(value.G, g);
            setValues(value.B, b);
            setValues(value.A, a);

            if (r.ChildNodes.Count > 0) keys.AppendChild(r);
            if (g.ChildNodes.Count > 0) keys.AppendChild(g);
            if (b.ChildNodes.Count > 0) keys.AppendChild(b);
            if (a.ChildNodes.Count > 0) keys.AppendChild(a);

            if (keys.ChildNodes.Count > 0) e.AppendChild(keys);

            return e.ChildNodes.Count > 0 ? e : null;
        }
示例#3
0
        public override bool Update(System.Xml.XmlDocument document)
        {
            List <System.Xml.XmlNode> nodes = new List <System.Xml.XmlNode>();

            Action <System.Xml.XmlNode> collectNodes = null;

            collectNodes = (node) =>
            {
                if (node.Name == "Node")
                {
                    nodes.Add(node);
                }

                for (int i = 0; i < node.ChildNodes.Count; i++)
                {
                    collectNodes(node.ChildNodes[i]);
                }
            };

            collectNodes((XmlNode)document);

            foreach (var node in nodes)
            {
                var labs = node["LocationAbsValues"];

                if (labs != null)
                {
                    // old gravity and attractive force to new
                    if (labs["Type"] != null && labs["Type"].GetTextAsInt() != 0)
                    {
                        var lff = document.CreateElement("LocalForceField4");

                        var type = labs["Type"].GetTextAsInt();
                        if (type == 1)
                        {
                            lff.AppendChild(document.CreateTextElement("Type", (int)LocalForceFieldType.Gravity));
                        }
                        else if (type == 2)
                        {
                            lff.AppendChild(document.CreateTextElement("Type", (int)LocalForceFieldType.AttractiveForce));
                        }

                        if (labs["Gravity"] != null)
                        {
                            lff.AppendChild(labs["Gravity"]);
                        }

                        if (labs["AttractiveForce"] != null)
                        {
                            lff.AppendChild(labs["AttractiveForce"]);

                            if (lff["AttractiveForce"]["Force"] != null)
                            {
                                var force = lff["AttractiveForce"]["Force"].GetTextAsFloat();
                                lff.AppendChild(document.CreateTextElement("Power", force.ToString()));
                            }
                        }

                        labs.AppendChild(lff);
                    }

                    Action <XmlElement> convert = (elm) =>
                    {
                        if (elm == null)
                        {
                            return;
                        }

                        var typeInt = elm["Type"]?.GetTextAsInt();
                        var type    = typeInt.HasValue ? (Data.LocalForceFieldType)(typeInt.Value) : Data.LocalForceFieldType.None;

                        if (type == LocalForceFieldType.Turbulence)
                        {
                            if (elm["Turbulence"] != null && elm["Turbulence"]["Strength"] != null)
                            {
                                var strength = elm["Turbulence"]["Strength"].GetTextAsFloat();
                                elm.AppendChild(document.CreateTextElement("Power", strength.ToString()));
                            }
                        }

                        float defaultPower = 1.0f;

                        if (type == LocalForceFieldType.Turbulence)
                        {
                            defaultPower = 0.1f;
                        }

                        if (elm["Power"] != null)
                        {
                            defaultPower = elm["Power"].GetTextAsFloat();
                        }

                        if (type == LocalForceFieldType.Turbulence)
                        {
                            defaultPower *= 10.0f;
                        }

                        if (type == LocalForceFieldType.Vortex)
                        {
                            defaultPower /= 5.0f;
                        }

                        if (elm["Power"] != null)
                        {
                            elm.RemoveChild(elm["Power"]);
                        }

                        elm.AppendChild(document.CreateTextElement("Power", defaultPower.ToString()));

                        if (type == LocalForceFieldType.Vortex)
                        {
                            if (elm["Vortex"] == null)
                            {
                                elm.AppendChild(document.CreateElement("Vortex"));
                            }

                            elm["Vortex"].AppendChild(document.CreateTextElement("VortexType", ((int)ForceFieldVortexType.ConstantSpeed).ToString()));
                        }

                        if (type == LocalForceFieldType.Turbulence)
                        {
                            if (elm["Turbulence"] == null)
                            {
                                elm.AppendChild(document.CreateElement("Turbulence"));
                            }

                            elm["Turbulence"].AppendChild(document.CreateTextElement("TurbulenceType", ((int)ForceFieldTurbulenceType.Complicated).ToString()));
                        }
                    };

                    convert(labs["LocalForceField1"]);
                    convert(labs["LocalForceField2"]);
                    convert(labs["LocalForceField3"]);
                }
            }

            return(true);
        }
示例#4
0
文件: IO.cs 项目: kou-yeung/Effekseer
        public static XmlElement SaveToElement(XmlDocument doc, string element_name, Value.Path value, bool isClip)
        {
            if (value.DefaultValue == value.GetAbsolutePath()) return null;

            var text = "";
            if(!isClip && value.IsRelativeSaved)
                text = value.GetRelativePath();
            else
                text = value.GetAbsolutePath();

            return doc.CreateTextElement(element_name, text);
        }
示例#5
0
文件: IO.cs 项目: kou-yeung/Effekseer
        public static XmlElement SaveToElement(XmlDocument doc, string element_name, Value.FCurveVector3D value, bool isClip)
        {
            var e = doc.CreateElement(element_name);
            var keys = doc.CreateElement("Keys");
            var x = doc.CreateElement("X");
            var y = doc.CreateElement("Y");
            var z = doc.CreateElement("Z");

            int index = 0;

            Action<Value.FCurve<float>, XmlElement> setValues = (v, xml) =>
            {
                index = 0;

                var st = SaveToElement(doc, "StartType", v.StartType, isClip);
                var et = SaveToElement(doc, "EndType", v.EndType, isClip);
                var omax = SaveToElement(doc, "OffsetMax", v.OffsetMax, isClip);
                var omin = SaveToElement(doc, "OffsetMin", v.OffsetMin, isClip);
                var s = SaveToElement(doc, "Sampling", v.Sampling, isClip);

                if (st != null) xml.AppendChild(st);
                if (et != null) xml.AppendChild(et);
                if (omax != null) xml.AppendChild(omax);
                if (omin != null) xml.AppendChild(omin);
                if (s != null) xml.AppendChild(s);

                foreach (var k_ in v.Keys)
                {
                    var k = doc.CreateElement("Key" + index.ToString());
                    k.AppendChild(doc.CreateTextElement("Frame", k_.Frame.ToString()));
                    k.AppendChild(doc.CreateTextElement("Value", k_.ValueAsFloat.ToString()));
                    k.AppendChild(doc.CreateTextElement("LeftX", k_.LeftX.ToString()));
                    k.AppendChild(doc.CreateTextElement("LeftY", k_.LeftY.ToString()));
                    k.AppendChild(doc.CreateTextElement("RightX", k_.RightX.ToString()));
                    k.AppendChild(doc.CreateTextElement("RightY", k_.RightY.ToString()));

                    k.AppendChild(doc.CreateTextElement("InterpolationType", k_.InterpolationType.GetValueAsInt()));

                    xml.AppendChild(k);
                    index++;
                }
            };

            setValues(value.X, x);
            setValues(value.Y, y);
            setValues(value.Z, z);

            if (x.ChildNodes.Count > 0) keys.AppendChild(x);
            if (y.ChildNodes.Count > 0) keys.AppendChild(y);
            if (z.ChildNodes.Count > 0) keys.AppendChild(z);
            if (keys.ChildNodes.Count > 0) e.AppendChild(keys);

            return e.ChildNodes.Count > 0 ? e : null;
        }
示例#6
0
文件: IO.cs 项目: kou-yeung/Effekseer
        public static XmlElement SaveToElement(XmlDocument doc, string element_name, Value.EnumBase value, bool isClip)
        {
            if (value.GetValueAsInt() == value.GetDefaultValueAsInt()) return null;

            var text = value.GetValueAsInt().ToString();
            return doc.CreateTextElement(element_name, text);
        }
示例#7
0
文件: IO.cs 项目: kou-yeung/Effekseer
        public static XmlElement SaveToElement(XmlDocument doc, string element_name, Value.ColorWithRandom value, bool isClip)
        {
            var e = doc.CreateElement(element_name);
            var r = SaveToElement(doc, "R", value.R, isClip);
            var g = SaveToElement(doc, "G", value.G, isClip);
            var b = SaveToElement(doc, "B", value.B, isClip);
            var a = SaveToElement(doc, "A", value.A, isClip);
            var da = value.DefaultDrawnAs != value.DrawnAs ? doc.CreateTextElement("DrawnAs", (int)value.DrawnAs) : null;
            var cs = value.DefaultColorSpace != value.ColorSpace ? doc.CreateTextElement("ColorSpace", (int)value.ColorSpace) : null;

            if (r != null) e.AppendChild(r);
            if (g != null) e.AppendChild(g);
            if (b != null) e.AppendChild(b);
            if (a != null) e.AppendChild(a);
            if (da != null) e.AppendChild(da);
            if (cs != null) e.AppendChild(cs);
            return e.ChildNodes.Count > 0 ? e : null;
        }
示例#8
0
文件: IO.cs 项目: kou-yeung/Effekseer
        public static XmlElement SaveToElement(XmlDocument doc, string element_name, Value.Vector3DWithRandom value, bool isClip)
        {
            var e = doc.CreateElement(element_name);
            var x = SaveToElement(doc, "X", value.X, isClip);
            var y = SaveToElement(doc, "Y", value.Y, isClip);
            var z = SaveToElement(doc, "Z", value.Z, isClip);
            var da = value.DefaultDrawnAs != value.DrawnAs ? doc.CreateTextElement("DrawnAs", (int)value.DrawnAs) : null;

            if (x != null) e.AppendChild(x);
            if (y != null) e.AppendChild(y);
            if (z != null) e.AppendChild(z);
            if (da != null) e.AppendChild(da);

            return e.ChildNodes.Count > 0 ? e : null;
        }
示例#9
0
文件: IO.cs 项目: kou-yeung/Effekseer
        public static XmlElement SaveToElement(XmlDocument doc, string element_name, Value.FloatWithRandom value, bool isClip)
        {
            var e = doc.CreateElement(element_name);

            if(value.DefaultValueCenter != value.Center) e.AppendChild(doc.CreateTextElement("Center", value.Center.ToString()));
            if(value.DefaultValueMax != value.Max) e.AppendChild(doc.CreateTextElement("Max", value.Max.ToString()));
            if(value.DefaultValueMin != value.Min) e.AppendChild(doc.CreateTextElement("Min", value.Min.ToString()));
            if(value.DefaultDrawnAs != value.DrawnAs) e.AppendChild(doc.CreateTextElement("DrawnAs", (int)value.DrawnAs));

            return e.ChildNodes.Count > 0 ? e : null;
        }
示例#10
0
文件: IO.cs 项目: kou-yeung/Effekseer
 public static XmlElement SaveToElement(XmlDocument doc, string element_name, Value.Float value, bool isClip)
 {
     if (value.Value == value.DefaultValue) return null;
     var text = value.GetValue().ToString();
     return doc.CreateTextElement(element_name, text);
 }