BrashMonkey.Spriter.DataPlugins.SpriterDataUnity.RecordFrame C# (CSharp) Method

RecordFrame() private method

private RecordFrame ( SpriterAnimation anim, Transform characterRoot, SpriterMainlineKey keyframe, SpriterMainlineKey endKey, float currentTime, float frameRate, AnimationCurve>.Dictionary curves ) : void
anim SpriterAnimation
characterRoot UnityEngine.Transform
keyframe BrashMonkey.Spriter.Data.ObjectModel.SpriterMainlineKey
endKey BrashMonkey.Spriter.Data.ObjectModel.SpriterMainlineKey
currentTime float
frameRate float
curves AnimationCurve>.Dictionary
return void
        private void RecordFrame(SpriterAnimation anim, Transform characterRoot, SpriterMainlineKey keyframe,
		                         SpriterMainlineKey endKey, float currentTime, float frameRate,
		                         Dictionary<string, AnimationCurve>[] curves)
        {
            // Go through each sprite, keeping track of what is processed
            var processedSprites = new List<Component>();

            var bones = new Dictionary<int, Transform>();
            var scales = new Dictionary<int, Vector2>();

            foreach (SpriterMainlineBoneBase obj in keyframe.hierarchy.bones)
            {
                var obj1 = (obj as ISpriterTimelineBone);
                if (obj1 == null && obj is SpriterMainlineBoneRef)
                    obj1 = ((SpriterMainlineBoneRef)obj).target;
                if (obj1 == null)
                {
                    Debug.LogError("Unknown type");
                    continue;
                }

                SetObject(anim, characterRoot, keyframe == endKey, currentTime, frameRate, curves, processedSprites, obj1, bones, scales, obj);
            }

            //foreach(ISpriterSprite sprite in frame.sprites)
            foreach(SpriterMainlineObjectBase obj in keyframe.objects)
            {

                var obj1 = (obj as ISpriterTimelineObject);
                if (obj1 == null && obj is SpriterMainlineObjectRef)
                    obj1 = ((SpriterMainlineObjectRef)obj).target;
                if (obj1 == null)
                {
                    Debug.LogError("Unknown type");
                    continue;
                }

                SetObject(anim, characterRoot, keyframe == endKey, currentTime, frameRate, curves, processedSprites, obj1, bones, scales, null, obj);
            }

            //turn off all unused sprites
            foreach (var colorHelper in characterRoot.GetComponentsInChildren<SpriterNGUIColorHelper>())
            {
                //check if it's been used this keyframe
                if (!processedSprites.Contains(colorHelper))
                {
                    //grab the curve. If it doesn't exist, create it.
                    AnimationCurve val;
                    if (!curves[10].TryGetValue(GetRelativeName(colorHelper, characterRoot), out val))
                    {
                        val = new AnimationCurve();
                        curves[10].Add(GetRelativeName(colorHelper, characterRoot), val);
                    }

                    //If this is not the first keyframe, and the previous key was visible,
                    //make sure we step the value
                    int pos = val.AddKey(SteppedKeyframe(currentTime, 0));
                    if (pos > 0)
                    {
                        if (val.keys[pos - 1].value > 0)
                        {
                            val.AddKey(SteppedKeyframe(currentTime - (.001f / frameRate), val.keys[pos - 1].value));
                        }
                    }
                }
            }
        }