Exemple #1
0
    public override void Read(
        TagRecord _Tag
        , BinaryReader _GAFFileReader
        , ref GAFAnimationData _SharedData
        , ref GAFTimelineData _RootTimeline)
    {
        uint    id          = _GAFFileReader.ReadUInt32();
        uint    framesCount = _GAFFileReader.ReadUInt32();
        Rect    frameSize   = GAFReader.ReadRect(_GAFFileReader);
        Vector2 pivot       = GAFReader.ReadVector2(_GAFFileReader);
        byte    hasLinkage  = _GAFFileReader.ReadByte();
        string  linkageName = string.Empty;

        if (hasLinkage == 1)
        {
            linkageName = GAFReader.ReadString(_GAFFileReader);
        }

        var timeline = new GAFTimelineData(id, linkageName, framesCount, frameSize, pivot);

        _SharedData.timelines.Add((int)id, timeline);

        var tagReaders = GetTagsDictionary();

        while (_GAFFileReader.BaseStream.Position < _Tag.expectedStreamPosition)
        {
            TagRecord record;
            try
            {
                record = GAFReader.OpenTag(_GAFFileReader);
            }
            catch (System.Exception _exception)
            {
                throw new GAFException("GAF! GAFReader::Read - Failed to open tag! Stream position - " + _GAFFileReader.BaseStream.Position.ToString() + "\nException - " + _exception);
            }

            if (record.type != TagBase.TagType.TagInvalid &&
                tagReaders.ContainsKey(record.type))
            {
                try
                {
                    tagReaders[record.type].Read(record, _GAFFileReader, ref _SharedData, ref timeline);
                }
                catch (System.Exception _exception)
                {
                    throw new GAFException("GAF! GAFReader::Read - Failed to read tag - " + record.type.ToString() + "\n Exception - " + _exception.ToString(), record);
                }

                GAFReader.CheckTag(record, _GAFFileReader);
            }
            else
            {
                GAFReader.CloseTag(record, _GAFFileReader);
            }
        }
    }
Exemple #2
0
    public override void Read(
        TagRecord _Tag
        , BinaryReader _GAFFileReader
        , ref GAFAnimationData _SharedData
        , ref GAFTimelineData _CurrentTimeline)
    {
        float scale = _GAFFileReader.ReadSingle();

        Dictionary <uint, GAFTexturesData>     texturesInfos = new Dictionary <uint, GAFTexturesData>();
        Dictionary <uint, GAFAtlasElementData> atlasElements = new Dictionary <uint, GAFAtlasElementData>();

        byte atlasesCount = _GAFFileReader.ReadByte();

        for (byte i = 0; i < atlasesCount; ++i)
        {
            uint id           = _GAFFileReader.ReadUInt32();
            byte sourcesCount = _GAFFileReader.ReadByte();

            Dictionary <float, string> files = new Dictionary <float, string>();
            for (byte j = 0; j < sourcesCount; ++j)
            {
                string filename = GAFReader.ReadString(_GAFFileReader);
                float  csf      = _GAFFileReader.ReadSingle();

                files.Add(csf, filename);
            }

            texturesInfos.Add(id, new GAFTexturesData(id, files));
        }

        uint elementsCount = _GAFFileReader.ReadUInt32();

        for (uint i = 0; i < elementsCount; ++i)
        {
            Vector2 pivotPoint      = GAFReader.ReadVector2(_GAFFileReader);
            Vector2 origin          = GAFReader.ReadVector2(_GAFFileReader);
            float   elementScale    = _GAFFileReader.ReadSingle();
            float   width           = _GAFFileReader.ReadSingle();
            float   height          = _GAFFileReader.ReadSingle();
            uint    atlasIdx        = _GAFFileReader.ReadUInt32();
            uint    elementAtlasIdx = _GAFFileReader.ReadUInt32();
            bool    hasScale9Grid   = _GAFFileReader.ReadByte() == 1;
            Rect    scale9GridRect  = new Rect(0, 0, 0, 0);

            if (hasScale9Grid)
            {
                scale9GridRect = GAFReader.ReadRect(_GAFFileReader);
            }

            atlasElements.Add(elementAtlasIdx, new GAFAtlasElementData(
                                  elementAtlasIdx
                                  , pivotPoint.x
                                  , pivotPoint.y
                                  , origin.x
                                  , origin.y
                                  , width
                                  , height
                                  , atlasIdx
                                  , elementScale
                                  , scale9GridRect));
        }

        _CurrentTimeline.atlases.Add(new GAFAtlasData(scale, texturesInfos, atlasElements));
    }