Example #1
0
        public MidFrame[] GetMidFrames()
        {
            MidFrame[] frames = new MidFrame[atlasData.Length];

            for (int i = 0; i < atlasData.Length; i++)
            {
                AtlasData data  = atlasData[i];
                MidFrame  frame = new MidFrame();
                frame.name   = data.name;
                frame.offset = data.offset;
                frame.size   = data.size;
                // uv ---
                frame.uv = new Vector2[4];
                float sx  = data.position.x / sheetSize.x;
                float sy  = 1 - ((data.position.y + data.size.y) / sheetSize.y);
                float scx = data.size.x / sheetSize.x;
                float scy = data.size.y / sheetSize.y;
                if (data.rotated)
                {
                    sy          = 1 - ((data.position.y + data.size.x) / sheetSize.y);
                    scx         = data.size.y / sheetSize.x;
                    scy         = data.size.x / sheetSize.y;
                    frame.uv[3] = new Vector2(sx, sy + scy);
                    frame.uv[0] = new Vector2(sx + scx, sy + scy);
                    frame.uv[1] = new Vector2(sx + scx, sy);
                    frame.uv[2] = new Vector2(sx, sy);
                }
                else
                {
                    frame.uv[0] = new Vector2(sx, sy + scy);
                    frame.uv[1] = new Vector2(sx + scx, sy + scy);
                    frame.uv[2] = new Vector2(sx + scx, sy);
                    frame.uv[3] = new Vector2(sx, sy);
                }
                // ---

                frames[i] = frame;
            }
            return(frames);
        }
Example #2
0
        public override Atlas Parse()
        {
            if (!ValidXML())
            {
                return(null);
            }

            Vector2          sheetSize = Vector2.zero;
            List <AtlasData> data      = new List <AtlasData>();
            string           name      = null;

            if (xml.DocumentElement.Name == "plist")
            {
                XmlNodeList nodeList = xml.DocumentElement.SelectNodes("dict/key");
                for (int i = 0; i < nodeList.Count; i++)
                {
                    XmlNode frames = nodeList[i];
                    if (frames != null && frames.InnerText == "frames")
                    {
                        XmlNodeList subTextureNames = xml.DocumentElement.SelectNodes("dict/dict/key");
                        XmlNodeList subTextures     = xml.DocumentElement.SelectNodes("dict/dict/dict");
                        try {
                            for (int si = 0; si < subTextures.Count; si++)
                            {
                                subTexture = subTextures[si];
                                AtlasData ad = new AtlasData();

                                bool    rotated    = GetBool("rotated");
                                Rect    frame      = GetRect("frame");
                                Rect    colorRect  = GetRect("sourceColorRect");
                                Vector2 sourceSize = GetVector2("sourceSize");
                                Vector2 offset     = GetVector2("offset");

                                try {
                                    ad.name = subTextureNames[si].InnerText.Split('.')[0];
                                } catch (System.Exception) {
                                    ad.name = subTextureNames[si].InnerText;
                                }
                                ad.position = new Vector2(frame.xMin, frame.yMin);
                                if (rotated)
                                {
                                    ad.rotated = true;
                                }

                                ad.size      = new Vector2(colorRect.width, colorRect.height);
                                ad.frameSize = sourceSize;
                                ad.offset    = offset;

                                data.Add(ad);
                            }
                        } catch (System.Exception ERR) {
                            Debug.LogError("Orthello : Cocos2D Atlas Import error!");
                            Debug.LogError(ERR.Message);
                        }
                    }
                    else if (frames != null && frames.InnerText == "metadata")
                    {
                        XmlNode sizeNode = frames.NextSibling.SelectSingleNode("key[text()=\"size\"]");
                        if (sizeNode != null)
                        {
                            sheetSize = StringToVector2(sizeNode.NextSibling.InnerText);
                        }

                        XmlNode nameNode = frames.NextSibling.SelectSingleNode("key[text()=\"realTextureFileName\"]");
                        if (nameNode == null)
                        {
                            nameNode = frames.NextSibling.SelectSingleNode("key[text()=\"textureFileName\"]");
                        }
                        if (nameNode != null)
                        {
                            string[] sa = nameNode.NextSibling.InnerText.Split('.');
                            if (sa.Length > 0)
                            {
                                name = sa[0];
                            }
                        }
                    }
                }
            }

            Atlas atlas = new Atlas();

            atlas.atlasData = data.ToArray();
            atlas.sheetSize = sheetSize;
            atlas.name      = name;

            return(atlas);
        }