Esempio n. 1
0
 public override void Read(
     TagRecord _Tag
     , BinaryReader _GAFFileReader
     , ref GAFAnimationData _SharedData
     , ref GAFTimelineData _CurrentTimeline)
 {
 }
Esempio n. 2
0
    public override void Read(
        TagRecord _Tag
        , BinaryReader _GAFFileReader
        , ref GAFAnimationData _SharedData
        , ref GAFTimelineData _CurrentTimeline)
    {
        uint count = _GAFFileReader.ReadUInt32();

        for (uint i = 0; i < count; ++i)
        {
            string id = GAFReader.ReadString(_GAFFileReader);

            ushort start = _GAFFileReader.ReadUInt16();
            ushort end   = _GAFFileReader.ReadUInt16();

            var data = new GAFSequenceData(id, (uint)start, (uint)end);
            if (_CurrentTimeline == null)
            {
                _SharedData.rootTimeline.sequences.Add(data);
            }
            else
            {
                _CurrentTimeline.sequences.Add(data);
            }
        }
    }
Esempio n. 3
0
    public void Load(
        byte [] _AssetData
        , ref GAFAnimationData _SharedData)
    {
#if !UNITY_PRO_LICENSE && GAF_SUPPORT_COMPRESSED && UNITY_EDITOR
        if (PlayerSettings.apiCompatibilityLevel == ApiCompatibilityLevel.NET_2_0_Subset &&
            Application.platform != RuntimePlatform.WindowsEditor &&
            Application.platform != RuntimePlatform.WindowsPlayer)
        {
            GAFUtils.Warning("GAF! You are using compressed 'gaf' in free unity. Set API compatibility level as '.NET'!");
        }
#endif // !UNITY_PRO_LICENSE && GAF_SUPPORT_COMPRESSED && UNITY_EDITOR

        GAFHeader header = new GAFHeader();

        MemoryStream fstream = new MemoryStream(_AssetData);
        using (BinaryReader freader = new BinaryReader(fstream))
        {
            if (freader.BaseStream.Length > GAFHeader.headerDataOffset)
            {
                header.Read(freader);
                if (header.isValid)
                {
                    _SharedData = new GAFAnimationData();

                    _SharedData.majorVersion = header.majorVersion;
                    _SharedData.minorVersion = header.minorVersion;

                    switch (header.compression)
                    {
                    case GAFHeader.CompressionType.CompressedNone:
                        Read(freader, ref _SharedData);
                        break;

                    case GAFHeader.CompressionType.CompressedZip:
#if GAF_SUPPORT_COMPRESSED
                        using (ZlibStream zlibStream = new ZlibStream(fstream, CompressionMode.Decompress))
                        {
                            byte [] uncompressedBuffer = new byte[header.fileLength];
                            zlibStream.Read(uncompressedBuffer, 0, uncompressedBuffer.Length);

                            using (BinaryReader reader = new BinaryReader(new MemoryStream(uncompressedBuffer)))
                            {
                                Read(reader, ref _SharedData);
                            }
                        }
                        break;
#else
                        GAFUtils.Assert(false, "GAF. Compressed gaf format is not supported in your plugin!");
                        break;
#endif // GAF_SUPPORT_COMPRESSED
                    }
                }
            }
        }
    }
Esempio n. 4
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);
            }
        }
    }
Esempio n. 5
0
        public void initialize(byte[] _GAFData, string _GUID)
        {
            m_AssetData  = _GAFData;
            m_SharedData = null;
            m_GUID       = _GUID;

            m_AssetVersion = GAFSystem.AssetVersion;

            load();
        }
Esempio n. 6
0
    public void reload()
    {
        m_SharedData         = null;
        m_IsObjectsCollected = false;

        load();

#if UNITY_EDITOR
        initResources();
#endif // UNITY_EDITOR
    }
Esempio n. 7
0
    public void init(byte [] _GAFData)
    {
        m_AssetData          = _GAFData;
        m_SharedData         = null;
        m_IsObjectsCollected = false;

        load();

#if UNITY_EDITOR
        initResources();
#endif // UNITY_EDITOR
    }
Esempio n. 8
0
        public void load()
        {
            lock (m_Locker)
            {
#if UNITY_EDITOR
                if (m_AssetVersion < GAFSystem.AssetVersion &&
                    !EditorApplication.isPlayingOrWillChangePlaymode)
                {
                    upgrade();
                }
#endif // UNITY_EDITOR

                if (m_AssetVersion == GAFSystem.AssetVersion)
                {
                    if (!isLoaded &&
                        m_AssetData != null)
                    {
                        GAFReader reader = new GAFReader();
                        try
                        {
                            reader.Load(m_AssetData, ref m_SharedData);
                        }
                        catch (GAFException _Exception)
                        {
                            GAFUtils.Error(_Exception.Message);

                            m_SharedData = null;
                        }

                        if (isLoaded &&
                            !m_IsExternalDataCollected)
                        {
                            collectExternalData();

#if UNITY_EDITOR
                            if (!EditorApplication.isPlayingOrWillChangePlaymode)
                            {
                                EditorUtility.SetDirty(this);
                            }
#endif // UNITY_EDITOR
                        }
                    }
                }
                else
                {
                    GAFUtils.Log("Asset \"" + name + "\" was not upgraged!", string.Empty);
                }
            }
        }
Esempio n. 9
0
    public override void Read(
        TagRecord _Tag
        , BinaryReader _GAFFileReader
        , ref GAFAnimationData _SharedData
        , ref GAFTimelineData _CurrentTimeline)
    {
        uint count = _GAFFileReader.ReadUInt32();

        for (uint i = 0; i < count; ++i)
        {
            uint objectId          = _GAFFileReader.ReadUInt32();
            uint elementAtlasIdRef = _GAFFileReader.ReadUInt32();

            _SharedData.rootTimeline.masks.Add(new GAFMaskData(objectId, elementAtlasIdRef, GAFObjectType.Texture));
        }
    }
Esempio n. 10
0
    public override void Read(
        TagRecord _Tag
        , BinaryReader _GAFFileReader
        , ref GAFAnimationData _SharedData
        , ref GAFTimelineData _CurrentTimeline)
    {
        _SharedData.fps = _GAFFileReader.ReadByte();
        byte a = _GAFFileReader.ReadByte();
        byte r = _GAFFileReader.ReadByte();
        byte g = _GAFFileReader.ReadByte();
        byte b = _GAFFileReader.ReadByte();

        _SharedData.color  = new Color(r / 255f, g / 255f, b / 255f, a / 255f);
        _SharedData.width  = _GAFFileReader.ReadUInt16();
        _SharedData.height = _GAFFileReader.ReadUInt16();
    }
Esempio n. 11
0
    public override void Read(
        TagRecord _Tag
        , BinaryReader _GAFFileReader
        , ref GAFAnimationData _SharedData
        , ref GAFTimelineData _CurrentTimeline)
    {
        uint count = _GAFFileReader.ReadUInt32();

        for (uint i = 0; i < count; ++i)
        {
            uint          objectId          = _GAFFileReader.ReadUInt32();
            uint          elementAtlasIdRef = _GAFFileReader.ReadUInt32();
            GAFObjectType type = (GAFObjectType)_GAFFileReader.ReadUInt16();

            _CurrentTimeline.objects.Add(new GAFObjectData(objectId, elementAtlasIdRef, type));
        }
    }
Esempio n. 12
0
    public override void Read(
        TagRecord _Tag
        , BinaryReader _GAFFileReader
        , ref GAFAnimationData _SharedData
        , ref GAFTimelineData _CurrentTimeline)
    {
        uint framesCount = _GAFFileReader.ReadUInt32();

        for (uint i = 0; i < framesCount; ++i)
        {
            uint         frameNumber = _GAFFileReader.ReadUInt32();
            GAFFrameData frame       = new GAFFrameData(frameNumber);

            bool hasChangesInDisplayList = _GAFFileReader.ReadByte() == 1;
            bool hasActions = _GAFFileReader.ReadByte() == 1;

            if (hasChangesInDisplayList)
            {
                uint statesCount = _GAFFileReader.ReadUInt32();
                for (uint j = 0; j < statesCount; ++j)
                {
                    frame.addState(ExctractState(_GAFFileReader));
                }
            }

            if (hasActions)
            {
                uint actionsCount = _GAFFileReader.ReadUInt32();
                for (uint j = 0; j < actionsCount; ++j)
                {
                    var type       = _GAFFileReader.ReadUInt32();
                    var actionData = new GAFActionData((GAFActionData.ActionType)type);

                    uint parametersCount = _GAFFileReader.ReadUInt32();
                    for (int k = 0; k < parametersCount; ++k)
                    {
                        actionData.parameters.Add(GAFReader.ReadString(_GAFFileReader));
                    }
                }
            }

            _CurrentTimeline.frames.Add(frame.frameNumber, frame);
        }
    }
Esempio n. 13
0
    public override void Read(
        TagRecord _Tag
        , BinaryReader _GAFFileReader
        , ref GAFAnimationData _SharedData
        , ref GAFTimelineData _CurrentTimeline)
    {
        uint framesCount = _GAFFileReader.ReadUInt32();

        for (uint i = 0; i < framesCount; ++i)
        {
            uint         frameNumber = _GAFFileReader.ReadUInt32();
            GAFFrameData frame       = new GAFFrameData(frameNumber);

            uint statesCount = _GAFFileReader.ReadUInt32();
            for (uint j = 0; j < statesCount; ++j)
            {
                frame.addState(ExctractState(_GAFFileReader));
            }

            _SharedData.rootTimeline.frames.Add(frame.frameNumber, frame);
        }
    }
Esempio n. 14
0
    public void load()
    {
        lock (m_Locker)
        {
#if UNITY_EDITOR
            m_GUID = AssetDatabase.AssetPathToGUID(AssetDatabase.GetAssetPath(this));

            m_Version = GAFSystem.Version;
#endif // UNITY_EDITOR

            if (!isLoaded)
            {
                if (m_AssetData != null)
                {
                    GAFReader reader = new GAFReader();
                    try
                    {
                        reader.Load(m_AssetData, ref m_SharedData);
                    }
                    catch (GAFException _Exception)
                    {
                        GAFUtils.Error(_Exception.Message);

                        m_SharedData = null;
                    }
                }
            }

            if (isLoaded)
            {
#if UNITY_EDITOR
                if (!m_IsObjectsCollected)
                {
                    initObjectsLists();
                }
#endif // UNITY_EDITOR
            }
        }
    }
Esempio n. 15
0
    public override void Read(
        TagRecord _Tag
        , BinaryReader _GAFFileReader
        , ref GAFAnimationData _SharedData
        , ref GAFTimelineData _CurrentTimeline)
    {
        uint count = _GAFFileReader.ReadUInt32();

        for (uint i = 0; i < count; ++i)
        {
            uint   objectIdRef = _GAFFileReader.ReadUInt32();
            string name        = GAFReader.ReadString(_GAFFileReader);

            var data = new GAFNamedPartData(objectIdRef, name);
            if (_CurrentTimeline == null)
            {
                _SharedData.rootTimeline.namedParts.Add(data);
            }
            else
            {
                _CurrentTimeline.namedParts.Add(data);
            }
        }
    }
Esempio n. 16
0
    public override void Read(
        TagRecord _Tag
        , BinaryReader _GAFFileReader
        , ref GAFAnimationData _SharedData
        , ref GAFTimelineData _CurrentTimeline)
    {
        float scale = _GAFFileReader.ReadSingle();

        if (!_SharedData.scales.Contains(scale))
        {
            _SharedData.scales.Add(scale);
        }

        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();

                if (!_SharedData.csfs.Contains(csf))
                {
                    _SharedData.csfs.Add(csf);
                }

                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();

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

        _SharedData.rootTimeline.atlases.Add(new GAFAtlasData(scale, texturesInfos, atlasElements));
    }
Esempio n. 17
0
        public void load()
        {
            lock (m_Locker)
            {
            #if UNITY_EDITOR
                if (m_AssetVersion < GAFSystem.AssetVersion &&
                    !EditorApplication.isPlayingOrWillChangePlaymode)
                {
                    upgrade();
                }
            #endif // UNITY_EDITOR

                if (m_AssetVersion == GAFSystem.AssetVersion)
                {
                    if (!isLoaded &&
                         m_AssetData != null)
                    {
                        GAFReader reader = new GAFReader();
                        try
                        {
                            reader.Load(m_AssetData, ref m_SharedData);
                        }
                        catch (GAFException _Exception)
                        {
                            GAFUtils.Error(_Exception.Message);

                            m_SharedData = null;
                        }

                        if (isLoaded &&
                            !m_IsExternalDataCollected)
                        {
                            collectExternalData();

            #if UNITY_EDITOR
                            if (!EditorApplication.isPlayingOrWillChangePlaymode)
                                EditorUtility.SetDirty(this);
            #endif // UNITY_EDITOR
                        }
                    }
                }
                else
                {
                    GAFUtils.Log("Asset \"" + name + "\" was not upgraged!", string.Empty);
                }
            }
        }
Esempio n. 18
0
        public void initialize(byte[] _GAFData, string _GUID)
        {
            m_AssetData		= _GAFData;
            m_SharedData	= null;
            m_GUID			= _GUID;

            m_AssetVersion = GAFSystem.AssetVersion;

            load();
        }
Esempio n. 19
0
    private void Read(
        BinaryReader _GAFFileReader
        , ref GAFAnimationData _SharedData)
    {
        var tagReaders = GetTagsDictionary(_SharedData.majorVersion);

        if (_SharedData.majorVersion >= TimelinesBaseVersion)
        {
            uint scalesCount = _GAFFileReader.ReadUInt32();
            for (uint i = 0; i < scalesCount; ++i)
            {
                _SharedData.scales.Add(_GAFFileReader.ReadSingle());
            }

            uint csfsCount = _GAFFileReader.ReadUInt32();
            for (uint i = 0; i < csfsCount; ++i)
            {
                _SharedData.csfs.Add(_GAFFileReader.ReadSingle());
            }
        }
        else
        {
            uint    id          = 0;
            string  linkageName = "rootTimeline";
            uint    framesCount = (uint)_GAFFileReader.ReadUInt16();
            Rect    frameSize   = ReadRect(_GAFFileReader);
            Vector2 pivot       = ReadVector2(_GAFFileReader);

            _SharedData.timelines.Add((int)id, new GAFTimelineData(id, linkageName, framesCount, frameSize, pivot));
        }

        while (_GAFFileReader.BaseStream.Position < _GAFFileReader.BaseStream.Length)
        {
            TagRecord record;
            try
            {
                record = 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
                {
                    GAFTimelineData data = null;
                    tagReaders[record.type].Read(record, _GAFFileReader, ref _SharedData, ref data);
                }
                catch (System.Exception _exception)
                {
                    throw new GAFException("GAF! GAFReader::Read - Failed to read tag - " + record.type.ToString() + "\n Exception - " + _exception.ToString(), record);
                }

                CheckTag(record, _GAFFileReader);
            }
            else
            {
                CloseTag(record, _GAFFileReader);
            }
        }

        if (_SharedData != null)
        {
            foreach (var timeline in _SharedData.timelines.Values)
            {
                timeline.sequences.Add(new GAFSequenceData("Default", 1, timeline.framesCount));
            }
        }
    }