예제 #1
0
        public static bool ParseCellMaps(UFile file, List <UFile> textures, List <SpriteStudioCell> cells)
        {
            var xmlDoc = XDocument.Load(file);

            if (xmlDoc.Root == null)
            {
                return(false);
            }

            var nameSpace = xmlDoc.Root.Name.Namespace;

            var cellMaps = xmlDoc.Descendants(nameSpace + "cellmapNames").Descendants(nameSpace + "value");

            foreach (var cellMap in cellMaps)
            {
                var mapFile = UPath.Combine(file.GetFullDirectory(), new UFile(cellMap.Value));
                var cellDoc = XDocument.Load(mapFile);
                if (cellDoc.Root == null)
                {
                    return(false);
                }

                var cnameSpace = cellDoc.Root.Name.Namespace;

                var cellNodes = cellDoc.Descendants(nameSpace + "cell");
                foreach (var cellNode in cellNodes)
                {
                    var cell = new SpriteStudioCell
                    {
                        Name         = cellNode.Descendants(cnameSpace + "name").First().Value,
                        TextureIndex = textures.Count
                    };

                    var posData    = cellNode.Descendants(nameSpace + "pos").First().Value;
                    var posValues  = Regex.Split(posData, "\\s+");
                    var sizeData   = cellNode.Descendants(nameSpace + "size").First().Value;
                    var sizeValues = Regex.Split(sizeData, "\\s+");
                    cell.Rectangle = new RectangleF(
                        float.Parse(posValues[0], CultureInfo.InvariantCulture),
                        float.Parse(posValues[1], CultureInfo.InvariantCulture),
                        float.Parse(sizeValues[0], CultureInfo.InvariantCulture),
                        float.Parse(sizeValues[1], CultureInfo.InvariantCulture));

                    var pivotData   = cellNode.Descendants(nameSpace + "pivot").First().Value;
                    var pivotValues = Regex.Split(pivotData, "\\s+");
                    cell.Pivot = new Vector2((float.Parse(pivotValues[0], CultureInfo.InvariantCulture) + 0.5f) * cell.Rectangle.Width, (-float.Parse(pivotValues[1], CultureInfo.InvariantCulture) + 0.5f) * cell.Rectangle.Height);

                    cells.Add(cell);
                }

                var textPath = cellDoc.Descendants(nameSpace + "imagePath").First().Value;

                textures.Add(UPath.Combine(file.GetFullDirectory(), new UFile(textPath)));
            }

            return(true);
        }
예제 #2
0
        public static bool ParseCellMaps(UFile file, List<UFile> textures, List<SpriteStudioCell> cells)
        {
            var xmlDoc = XDocument.Load(file);
            if (xmlDoc.Root == null) return false;

            var nameSpace = xmlDoc.Root.Name.Namespace;

            var cellMaps = xmlDoc.Descendants(nameSpace + "cellmapNames").Descendants(nameSpace + "value");

            foreach (var cellMap in cellMaps)
            {
                var mapFile = UPath.Combine(file.GetFullDirectory(), new UFile(cellMap.Value));
                var cellDoc = XDocument.Load(mapFile);
                if (cellDoc.Root == null) return false;

                var cnameSpace = cellDoc.Root.Name.Namespace;

                var cellNodes = cellDoc.Descendants(nameSpace + "cell");
                foreach (var cellNode in cellNodes)
                {
                    var cell = new SpriteStudioCell
                    {
                        Name = cellNode.Descendants(cnameSpace + "name").First().Value,
                        TextureIndex = textures.Count
                    };

                    var posData = cellNode.Descendants(nameSpace + "pos").First().Value;
                    var posValues = Regex.Split(posData, "\\s+");
                    var sizeData = cellNode.Descendants(nameSpace + "size").First().Value;
                    var sizeValues = Regex.Split(sizeData, "\\s+");
                    cell.Rectangle = new RectangleF(
                        float.Parse(posValues[0], CultureInfo.InvariantCulture),
                        float.Parse(posValues[1], CultureInfo.InvariantCulture),
                        float.Parse(sizeValues[0], CultureInfo.InvariantCulture),
                        float.Parse(sizeValues[1], CultureInfo.InvariantCulture));

                    var pivotData = cellNode.Descendants(nameSpace + "pivot").First().Value;
                    var pivotValues = Regex.Split(pivotData, "\\s+");
                    cell.Pivot = new Vector2((float.Parse(pivotValues[0], CultureInfo.InvariantCulture) + 0.5f) * cell.Rectangle.Width, (-float.Parse(pivotValues[1], CultureInfo.InvariantCulture) + 0.5f) * cell.Rectangle.Height);

                    cells.Add(cell);
                }

                var textPath = cellDoc.Descendants(nameSpace + "imagePath").First().Value;

                textures.Add(UPath.Combine(file.GetFullDirectory(), new UFile(textPath)));
            }

            return true;
        }