Example #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);
            }
        }
    }
Example #2
0
 public override void Read(
     TagRecord _Tag
     , BinaryReader _GAFFileReader
     , ref GAFAnimationData _SharedData
     , ref GAFTimelineData _CurrentTimeline)
 {
 }
Example #3
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);
            }
        }
    }
Example #4
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));
        }
    }
Example #5
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();
    }
Example #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          objectId          = _GAFFileReader.ReadUInt32();
            uint          elementAtlasIdRef = _GAFFileReader.ReadUInt32();
            GAFObjectType type = (GAFObjectType)_GAFFileReader.ReadUInt16();

            _CurrentTimeline.objects.Add(new GAFObjectData(objectId, elementAtlasIdRef, type));
        }
    }
Example #7
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);
        }
    }
        protected override AnimationClip createAnimationClip(GAFTimelineData _Timeline, GAFSequenceData _Sequence, string _Path)
        {
            var animationClip = new AnimationClip()
            {
                frameRate = 30
                ,
                name = _Sequence.name
            };

            var framesCount  = _Sequence.endFrame - _Sequence.startFrame + 1;
            var timeInterval = framesCount / animationClip.frameRate / framesCount;

            var time   = 0f;
            var events = new AnimationEvent[framesCount];

            for (uint i = _Sequence.startFrame, j = 0; i <= _Sequence.endFrame; i++, j++)
            {
                var animationEvent = new AnimationEvent();
                animationEvent.functionName = i != _Sequence.startFrame ? "updateToFrameAnimator" : "updateToFrameAnimatorWithRefresh";
                animationEvent.intParameter = (int)i;
                animationEvent.time         = time;

                events[j] = animationEvent;

                time += timeInterval;
            }

            var serializedObj = new SerializedObject(animationClip);
            var settings      = serializedObj.FindProperty("m_AnimationClipSettings");
            var loopTime      = settings.FindPropertyRelative("m_LoopTime");

            loopTime.boolValue = true;
            serializedObj.ApplyModifiedProperties();

#if !UNITY_5
            AnimationUtility.SetAnimationType(animationClip, ModelImporterAnimationType.Generic);
#endif
            AnimationUtility.SetAnimationEvents(animationClip, events);

            AssetDatabase.CreateAsset(animationClip, _Path);

            return(animationClip);
        }
        protected override AnimationClip createAnimationClip(GAFTimelineData _Timeline, GAFSequenceData _Sequence, string _Path)
        {
            var animationClip = new AnimationClip()
            {
                frameRate = 30
                ,
                name = _Sequence.name
            };

            var framesCount = _Sequence.endFrame - _Sequence.startFrame + 1;
            var timeInterval = framesCount / animationClip.frameRate / framesCount;

            var time = 0f;
            var events = new AnimationEvent[framesCount];
            for (uint i = _Sequence.startFrame, j = 0; i <= _Sequence.endFrame; i++, j++)
            {
                var animationEvent = new AnimationEvent();
                animationEvent.functionName = i != _Sequence.startFrame ? "updateToFrameAnimator" : "updateToFrameAnimatorWithRefresh";
                animationEvent.intParameter = (int)i;
                animationEvent.time = time;

                events[j] = animationEvent;

                time += timeInterval;
            }

            var serializedObj = new SerializedObject(animationClip);
            var settings = serializedObj.FindProperty("m_AnimationClipSettings");
            var loopTime = settings.FindPropertyRelative("m_LoopTime");

            loopTime.boolValue = true;
            serializedObj.ApplyModifiedProperties();

            #if !UNITY_5
            AnimationUtility.SetAnimationType(animationClip, ModelImporterAnimationType.Generic);
            #endif
            AnimationUtility.SetAnimationEvents(animationClip, events);

            AssetDatabase.CreateAsset(animationClip, _Path);

            return animationClip;
        }
Example #10
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);
        }
    }
Example #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   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);
            }
        }
    }
		protected override void createAnimations(GAFTimelineData _Timeline, AnimatorController _AnimatorController, string _AnimationsPath)
		{
#if !UNITY_5
			var layer 				= _AnimatorController.GetLayer(0);
			var stateMachine 		= layer.stateMachine;
			var isNewStateMachine 	= stateMachine.stateCount == 0;

			var i = 0;
			foreach (var sequence in _Timeline.sequences)
			{
				int stateFoundIndex = -1;

				for (int stateIndex = 0; stateIndex < stateMachine.stateCount; ++stateIndex)
				{
					if (stateMachine.GetState(stateIndex).name == sequence.name)
					{
						stateFoundIndex = stateIndex;
						break;
					}
				}

				var clipName = _AnimatorController.name + "_" + sequence.name + ".anim";
				var clip = AssetDatabase.LoadAssetAtPath(_AnimationsPath + clipName, typeof(AnimationClip)) as AnimationClip;
				if (clip == null)
					clip = createAnimationClip(_Timeline, sequence, _AnimationsPath + clipName);

				State state = null;
				if (stateFoundIndex >= 0)
				{
					state = stateMachine.GetState(stateFoundIndex);
				}
				else
				{
					state = stateMachine.AddState(sequence.name);
					state.position = new Vector3(0, 50f, 0f) * i;
				}

				state.SetAnimationClip(clip);
				if (isNewStateMachine)
                {
					if (sequence.name.ToLower() == "default")
					{
						stateMachine.defaultState = state;
					}
				}
				++i;

			}
#else
			var layer				= _AnimatorController.layers[0];
			var stateMachine		= layer.stateMachine;
			var isNewStateMachine 	= stateMachine.states.Length == 0;

            var i = 0;

			foreach (var sequence in _Timeline.sequences)
			{
				int stateFoundIndex = -1;

				for (int stateIndex = 0; stateIndex < stateMachine.states.Length; ++stateIndex)
				{
					if (stateMachine.states[stateIndex].state.name == sequence.name)
					{
						stateFoundIndex = stateIndex;
						break;
					}
				}

				var clipName	= _AnimatorController.name + "_" + sequence.name + ".anim";
				var clip		= AssetDatabase.LoadAssetAtPath(_AnimationsPath + clipName, typeof(AnimationClip)) as AnimationClip;
				if (clip == null)
					clip = createAnimationClip(_Timeline, sequence, _AnimationsPath + clipName);

				AnimatorState state = null;
				if (stateFoundIndex >= 0)
				{
					state = stateMachine.states[stateFoundIndex].state;
				}
				else
				{
					state = stateMachine.AddState(sequence.name, new Vector3(0, 50f, 0f) * i);
				}

				state.motion = clip;

				if (isNewStateMachine)
				{
					if (sequence.name.ToLower() == "default")
					{
						stateMachine.defaultState = state;
					}
				}
				++i;
			}
#endif // !UNITY_5
		}
Example #13
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));
    }
Example #14
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));
            }
        }
    }
        protected override void createAnimations(GAFTimelineData _Timeline, AnimatorController _AnimatorController, string _AnimationsPath)
        {
#if !UNITY_5
            var layer             = _AnimatorController.GetLayer(0);
            var stateMachine      = layer.stateMachine;
            var isNewStateMachine = stateMachine.stateCount == 0;

            var i = 0;
            foreach (var sequence in _Timeline.sequences)
            {
                int stateFoundIndex = -1;

                for (int stateIndex = 0; stateIndex < stateMachine.stateCount; ++stateIndex)
                {
                    if (stateMachine.GetState(stateIndex).name == sequence.name)
                    {
                        stateFoundIndex = stateIndex;
                        break;
                    }
                }

                var clipName = _AnimatorController.name + "_" + sequence.name + ".anim";
                var clip     = AssetDatabase.LoadAssetAtPath(_AnimationsPath + clipName, typeof(AnimationClip)) as AnimationClip;
                if (clip == null)
                {
                    clip = createAnimationClip(_Timeline, sequence, _AnimationsPath + clipName);
                }

                State state = null;
                if (stateFoundIndex >= 0)
                {
                    state = stateMachine.GetState(stateFoundIndex);
                }
                else
                {
                    state          = stateMachine.AddState(sequence.name);
                    state.position = new Vector3(0, 50f, 0f) * i;
                }

                state.SetAnimationClip(clip);
                if (isNewStateMachine)
                {
                    if (sequence.name.ToLower() == "default")
                    {
                        stateMachine.defaultState = state;
                    }
                }
                ++i;
            }
#else
            var layer             = _AnimatorController.layers[0];
            var stateMachine      = layer.stateMachine;
            var isNewStateMachine = stateMachine.states.Length == 0;

            var i = 0;

            foreach (var sequence in _Timeline.sequences)
            {
                int stateFoundIndex = -1;

                for (int stateIndex = 0; stateIndex < stateMachine.states.Length; ++stateIndex)
                {
                    if (stateMachine.states[stateIndex].state.name == sequence.name)
                    {
                        stateFoundIndex = stateIndex;
                        break;
                    }
                }

                var clipName = _AnimatorController.name + "_" + sequence.name + ".anim";
                var clip     = AssetDatabase.LoadAssetAtPath(_AnimationsPath + clipName, typeof(AnimationClip)) as AnimationClip;
                if (clip == null)
                {
                    clip = createAnimationClip(_Timeline, sequence, _AnimationsPath + clipName);
                }

                AnimatorState state = null;
                if (stateFoundIndex >= 0)
                {
                    state = stateMachine.states[stateFoundIndex].state;
                }
                else
                {
                    state = stateMachine.AddState(sequence.name, new Vector3(0, 50f, 0f) * i);
                }

                state.motion = clip;

                if (isNewStateMachine)
                {
                    if (sequence.name.ToLower() == "default")
                    {
                        stateMachine.defaultState = state;
                    }
                }
                ++i;
            }
#endif // !UNITY_5
        }