示例#1
0
        private static void FillNodeData(XNamespace nameSpace, XContainer part, List <SpriteStudioCell> cells, out NodeAnimationData nodeData)
        {
            nodeData = new NodeAnimationData();

            var attribs = part.Descendants(nameSpace + "attribute");

            foreach (var attrib in attribs)
            {
                var tag  = attrib.Attributes("tag").First().Value;
                var keys = attrib.Descendants(nameSpace + "key");

                switch (tag)
                {
                case "CELL":
                {
                    var keyValues = new List <Dictionary <string, string> >();
                    foreach (var key in keys)
                    {
                        var values    = new Dictionary <string, string>();
                        var cellName  = key.Descendants(nameSpace + "value").First().Descendants(nameSpace + "name").First().Value;
                        var index     = 0;
                        var realIndex = -1;
                        foreach (var cell in cells)
                        {
                            if (cell.Name == cellName)
                            {
                                realIndex = index;
                            }
                            index++;
                        }
                        values.Add("time", key.Attribute("time").Value);
                        values.Add("curve", key.Attribute("ipType") != null ? key.Attribute("ipType").Value : "linear");
                        values.Add("value", realIndex.ToString(CultureInfo.InvariantCulture));

                        keyValues.Add(values);
                    }
                    nodeData.Data.Add(tag, keyValues);
                }
                break;

                case "VCOL":
                {
                    var xElements   = keys as XElement[] ?? keys.ToArray();
                    var blendValues = new List <Dictionary <string, string> >();
                    foreach (var key in xElements)
                    {
                        var values    = new Dictionary <string, string>();
                        var blendType = key.Descendants(nameSpace + "value").First().Descendants(nameSpace + "blendType").First().Value;

                        values.Add("time", key.Attribute("time").Value);
                        values.Add("curve", key.Attribute("ipType") != null ? key.Attribute("ipType").Value : "linear");
                        values.Add("value", ((int)ParseBlending(blendType)).ToString(CultureInfo.InvariantCulture));

                        blendValues.Add(values);
                    }
                    nodeData.Data.Add("COLB", blendValues);

                    var colorValues = new List <Dictionary <string, string> >();
                    foreach (var key in xElements)
                    {
                        var values   = new Dictionary <string, string>();
                        var colorInt = key.Descendants(nameSpace + "value").First().Descendants(nameSpace + "rgba").First().Value;
                        var color    = int.Parse(colorInt, NumberStyles.HexNumber, CultureInfo.InvariantCulture);

                        values.Add("time", key.Attribute("time").Value);
                        values.Add("curve", key.Attribute("ipType") != null ? key.Attribute("ipType").Value : "linear");
                        values.Add("value", color.ToString(CultureInfo.InvariantCulture));

                        colorValues.Add(values);
                    }
                    nodeData.Data.Add("COLV", colorValues);

                    var factorValues = new List <Dictionary <string, string> >();
                    foreach (var key in xElements)
                    {
                        var values    = new Dictionary <string, string>();
                        var rateValue = key.Descendants(nameSpace + "value").First().Descendants(nameSpace + "rate").First().Value;

                        values.Add("time", key.Attribute("time").Value);
                        values.Add("curve", key.Attribute("ipType") != null ? key.Attribute("ipType").Value : "linear");
                        values.Add("value", rateValue);

                        factorValues.Add(values);
                    }
                    nodeData.Data.Add("COLF", factorValues);
                }
                break;

                default:
                {
                    var values = keys.Where(key => key.Descendants(nameSpace + "value").FirstOrDefault() != null).Select(key => new Dictionary <string, string>
                        {
                            { "time", key.Attribute("time").Value },
                            { "curve", key.Attribute("ipType") != null ? key.Attribute("ipType").Value : "linear" },
                            { "value", key.Descendants(nameSpace + "value").First().Value }
                        }).ToList();
                    nodeData.Data.Add(tag, values);
                }
                break;
                }
            }
        }
        private static void FillNodeData(XNamespace nameSpace, XContainer part, List<SpriteStudioCell> cells, out NodeAnimationData nodeData)
        {
            nodeData = new NodeAnimationData();

            var attribs = part.Descendants(nameSpace + "attribute");
            foreach (var attrib in attribs)
            {
                var tag = attrib.Attributes("tag").First().Value;
                var keys = attrib.Descendants(nameSpace + "key");

                switch (tag)
                {
                    case "CELL":
                        {
                            var keyValues = new List<Dictionary<string, string>>();
                            foreach (var key in keys)
                            {
                                var values = new Dictionary<string, string>();
                                var cellName = key.Descendants(nameSpace + "value").First().Descendants(nameSpace + "name").First().Value;
                                var index = 0;
                                var realIndex = -1;
                                foreach (var cell in cells)
                                {
                                    if (cell.Name == cellName)
                                    {
                                        realIndex = index;
                                    }
                                    index++;
                                }
                                values.Add("time", key.Attribute("time").Value);
                                values.Add("curve", key.Attribute("ipType") != null ? key.Attribute("ipType").Value : "linear");
                                values.Add("value", realIndex.ToString(CultureInfo.InvariantCulture));

                                keyValues.Add(values);
                            }
                            nodeData.Data.Add(tag, keyValues);
                        }
                        break;

                    case "VCOL":
                        {
                            var xElements = keys as XElement[] ?? keys.ToArray();
                            var blendValues = new List<Dictionary<string, string>>();
                            foreach (var key in xElements)
                            {
                                var values = new Dictionary<string, string>();
                                var blendType = key.Descendants(nameSpace + "value").First().Descendants(nameSpace + "blendType").First().Value;

                                values.Add("time", key.Attribute("time").Value);
                                values.Add("curve", key.Attribute("ipType") != null ? key.Attribute("ipType").Value : "linear");
                                values.Add("value", ((int)ParseBlending(blendType)).ToString(CultureInfo.InvariantCulture));

                                blendValues.Add(values);
                            }
                            nodeData.Data.Add("COLB", blendValues);

                            var colorValues = new List<Dictionary<string, string>>();
                            foreach (var key in xElements)
                            {
                                var values = new Dictionary<string, string>();
                                var colorInt = key.Descendants(nameSpace + "value").First().Descendants(nameSpace + "rgba").First().Value;
                                var color = int.Parse(colorInt, NumberStyles.HexNumber, CultureInfo.InvariantCulture);

                                values.Add("time", key.Attribute("time").Value);
                                values.Add("curve", key.Attribute("ipType") != null ? key.Attribute("ipType").Value : "linear");
                                values.Add("value", color.ToString(CultureInfo.InvariantCulture));

                                colorValues.Add(values);
                            }
                            nodeData.Data.Add("COLV", colorValues);

                            var factorValues = new List<Dictionary<string, string>>();
                            foreach (var key in xElements)
                            {
                                var values = new Dictionary<string, string>();
                                var rateValue = key.Descendants(nameSpace + "value").First().Descendants(nameSpace + "rate").First().Value;

                                values.Add("time", key.Attribute("time").Value);
                                values.Add("curve", key.Attribute("ipType") != null ? key.Attribute("ipType").Value : "linear");
                                values.Add("value", rateValue);

                                factorValues.Add(values);
                            }
                            nodeData.Data.Add("COLF", factorValues);
                        }
                        break;

                    default:
                        {
                            var values = keys.Where(key => key.Descendants(nameSpace + "value").FirstOrDefault() != null).Select(key => new Dictionary<string, string>
                            {
                                { "time", key.Attribute("time").Value },
                                { "curve", key.Attribute("ipType") != null ? key.Attribute("ipType").Value : "linear" },
                                { "value", key.Descendants(nameSpace + "value").First().Value }
                            }).ToList();
                            nodeData.Data.Add(tag, values);
                        }
                        break;
                }
            }
        }