/// <summary>
    /// Import atlasData from sparrow xml
    /// </summary>
    protected override OTAtlasData[] Import()
    {
        if (!ValidXML())
        {
            return new OTAtlasData[] { }
        }
        ;

        List <OTAtlasData> data = new List <OTAtlasData>();

        if (xml.rootName == "Imageset")
        {
            OTDataset dsTextures = xml.Dataset("Image");

            while (!dsTextures.EOF)
            {
                OTAtlasData ad = new OTAtlasData();

                ad.name      = dsTextures.AsString("Name");
                ad.position  = new Vector2(dsTextures.AsInt("XPos"), dsTextures.AsInt("YPos"));
                ad.size      = new Vector2(dsTextures.AsInt("Width"), dsTextures.AsInt("Height"));
                ad.frameSize = new Vector2(dsTextures.AsInt("Width"), dsTextures.AsInt("Height"));
                ad.offset    = Vector2.zero;

                data.Add(ad);
                dsTextures.Next();
            }
        }
        return(data.ToArray());
    }
}
Beispiel #2
0
    /// <summary>
    /// Import atlasData from sparrow xml
    /// </summary>
    protected override OTAtlasData[] Import()
    {
        if (!ValidXML())
        {
            return new OTAtlasData[] { }
        }
        ;

        List <OTAtlasData> data = new List <OTAtlasData>();

        if (xml.rootName == "TextureAtlas")
        {
            OTDataset dsTextures = xml.Dataset("SubTexture");

            while (!dsTextures.EOF)
            {
                OTAtlasData ad = new OTAtlasData();

                ad.name      = dsTextures.AsString("name");
                ad.position  = new Vector2(dsTextures.AsInt("x"), dsTextures.AsInt("y"));
                ad.size      = new Vector2(dsTextures.AsInt("width"), dsTextures.AsInt("height"));
                ad.frameSize = new Vector2(dsTextures.AsInt("frameWidth"), dsTextures.AsInt("frameHeight"));
                ad.offset    = new Vector2(dsTextures.AsInt("frameX"), dsTextures.AsInt("frameY")) * -1;

                data.Add(ad);
                dsTextures.Next();
            }
        }
        return(data.ToArray());
    }
}
    /// <summary>
    /// Import atlasData from sparrow xml
    /// </summary>
    protected override OTAtlasData[] Import()
    {
        if (!ValidXML())
        {
            return new OTAtlasData[] { }
        }
        ;

        List <OTAtlasData> data = new List <OTAtlasData>();

        if (xml.rootName == "font")
        {
            OTDataset dsInfo = xml.Dataset("info");

            if (!dsInfo.EOF)
            {
                if (dsInfo.AsString("face") != "")
                {
                    if (name.IndexOf("Container (id=") == 0)
                    {
                        name = "Font " + dsInfo.AsString("face") + "-" + dsInfo.AsString("size");
                        if (dsInfo.AsString("bold") == "1")
                        {
                            name += "b";
                        }
                        if (dsInfo.AsString("italic") == "1")
                        {
                            name += "i";
                        }
                    }

                    metaType = "FONT";
                    OTDataset dsChars = xml.Dataset("chars");
                    while (!dsChars.EOF)
                    {
                        OTAtlasData ad = new OTAtlasData();

                        ad.name     = "" + dsChars.AsInt("id");
                        ad.position = new Vector2(dsChars.AsInt("x"), dsChars.AsInt("y"));
                        ad.size     = new Vector2(dsChars.AsInt("width"), dsChars.AsInt("height"));
                        ad.offset   = new Vector2(dsChars.AsInt("xoffset"), dsChars.AsInt("yoffset"));

                        ad.AddMeta("dx", dsChars.AsString("xadvance"));
                        data.Add(ad);
                        dsChars.Next();
                    }
                }
            }
        }
        return(data.ToArray());
    }
Beispiel #4
0
    /// <summary>
    /// Import atlasData from sparrow xml
    /// </summary>
    protected override OTAtlasData[] Import()
    {
        if (!ValidXML())
        {
            return new OTAtlasData[] { }
        }
        ;

        List <OTAtlasData> data = new List <OTAtlasData>();

        if (xml.rootName == "plist")
        {
            OTDataset dsKeys = xml.Dataset("dict/key");

            while (!dsKeys.EOF)
            {
                string nodeText = xml.Value(dsKeys);
                if (nodeText == "frames")
                {
                    object dict = xml.Next(dsKeys);
                    if (xml.Name(dict) == "dict")
                    {
                        OTDataset dsTextureNames = xml.Dataset(dict, "key");
                        OTDataset dsTextures     = xml.Dataset(dict, "dict");
                        if (!dsTextureNames.EOF && !dsTextures.EOF && dsTextureNames.rowCount == dsTextures.rowCount)
                        {
                            try
                            {
                                while (!dsTextureNames.EOF && !dsTextures.EOF)
                                {
                                    OTAtlasData ad = new OTAtlasData();


                                    bool    rotated    = GetBool(dsTextures, "textureRotated");
                                    Rect    frame      = GetRect(dsTextures, "textureRect");
                                    Rect    colorRect  = GetRect(dsTextures, "spriteColorRect");
                                    Vector2 sourceSize = GetVector2(dsTextures, "spriteSourceSize");
                                    try
                                    {
                                        ad.name = xml.Value(dsTextureNames).Split('.')[0];
                                    }
                                    catch (System.Exception)
                                    {
                                        ad.name = xml.Value(dsTextureNames);
                                    }
                                    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    = new Vector2(colorRect.xMin, colorRect.yMin);

                                    data.Add(ad);

                                    dsTextureNames.Next();
                                    dsTextures.Next();
                                }
                            }
                            catch (System.Exception ERR)
                            {
                                Debug.LogError("Orthello : Zwoptext Atlas Import error!");
                                Debug.LogError(ERR.Message);
                                break;
                            }
                        }
                    }
                }
                else
                if (nodeText == "metadata")
                {
                    object dict = xml.Next(dsKeys);
                    if (xml.Name(dict) == "dict")
                    {
                        object el = xml.FindValue(dict, "key", "size");
                        if (el != null)
                        {
                            sheetSize = StringToVector2(xml.Value(xml.Next(el)));
                        }
                        el = xml.FindValue(dict, "key", "realTextureFileName");
                        if (el == null)
                        {
                            el = xml.FindValue(dict, "key", "textureFileName");
                        }
                        if (el != null)
                        {
                            string[] sa = xml.Value(xml.Next(el)).Split('.');
                            if (sa.Length > 0 && (name == "" || name.IndexOf("(id=-") >= 0))
                            {
                                name = sa[0];
                            }
                        }
                    }
                }
                dsKeys.Next();
            }
        }
        return(data.ToArray());
    }
}