Пример #1
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 == "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());
    }
}
Пример #2
0
    protected override object OpenDataset(object pdata, string elementName)
    {
        object nodes = null;

        if (available)
        {
            if (pdata == null)
            {
                nodes = this.Elements(elementName);
            }
            else
            {
                if (pdata is OTDataset)
                {
                    OTDataset dsData = (pdata as OTDataset);
                    if (dsData.data == null || dsData.EOF)
                    {
                        return(null);
                    }
                    else
                    {
                        nodes = this.Elements(this.Element(dsData, dsData.row), elementName);
                    }
                }
                else
                {
                    nodes = this.Elements(pdata, elementName);
                }
            }
        }
        return(nodes);
    }
Пример #3
0
    object DatasetElement(object dataset)
    {
        OTDataset ds = (OTDataset)dataset;

        if (ds.data != null && !ds.EOF)
        {
                        #if (UNITY_METRO || UNITY_WP8) && !UNITY_EDITOR
            List <XElement> list = null;
            if (ds.data is List <XElement> )
            {
                list = (ds.data) as List <XElement>;
            }
                        #else
            XmlNodeList list = null;
            if (ds.data is XmlNodeList)
            {
                list = (ds.data) as XmlNodeList;
            }
                        #endif
            if (list != null)
            {
                return(list[ds.row]);
            }
        }
        return(null);
    }
Пример #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 == "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());
    }
}
Пример #5
0
 public object Element(OTDataset ds, int row)
 {
     if (ds.data != null && ds.rowCount > row)
                     #if (UNITY_METRO || UNITY_WP8) && !UNITY_EDITOR
     { return(((List <XElement>)ds.data)[row]); }
             #else
     { return(((XmlNodeList)ds.data)[row]); }
             #endif
     return(null);
 }
Пример #6
0
    Vector2 GetVector2(OTDataset dict, string name)
    {
        object el = xml.FindValue(dict, "key", name);

        if (el != null)
        {
            return(StringToVector2(xml.Value(xml.Next(el))));
        }
        return(Vector2.zero);
    }
Пример #7
0
    Rect GetRect(OTDataset dict, string name)
    {
        object el = xml.FindValue(dict, "key", name);

        if (el != null)
        {
            return(StringToRect(xml.Value(xml.Next(el))));
        }
        return(new Rect(0, 0, 0, 0));
    }
Пример #8
0
    bool GetBool(OTDataset dict, string name)
    {
        object el = xml.FindValue(dict, "key", name);

        if (el != null)
        {
            return(xml.Name(xml.Next(el)).ToLower() == "true");
        }
        else
        {
            return(false);
        }
    }
    /// <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());
    }
Пример #10
0
 Vector2 GetVector2(OTDataset dict, string name)
 {
     object el = xml.FindValue(dict,"key",name);
     if (el != null)
         return StringToVector2(xml.Value(xml.Next(el)));
     return Vector2.zero;
 }
Пример #11
0
 Rect GetRect(OTDataset dict, string name)
 {
     object el = xml.FindValue(dict,"key",name);
     if (el != null)
         return StringToRect(xml.Value(xml.Next(el)));
     return new Rect(0, 0, 0, 0);
 }
Пример #12
0
 bool GetBool(OTDataset dict, string name)
 {
     object el = xml.FindValue(dict,"key",name);
     if (el!=null)
         return (xml.Name(xml.Next(el)).ToLower() == "true");
     else
         return false;
 }
Пример #13
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());
    }
}