Exemple #1
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);
            }
        }
    }
Exemple #2
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 #3
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);
                }
            }
        }
Exemple #4
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);
        }
    }
Exemple #5
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
            }
        }
    }
Exemple #6
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);
            }
        }
    }
Exemple #7
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));
    }
        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);
                }
            }
        }