public KeyBone(KeyBone that)
 {
     this.Angle = that.Angle;
     this.ScaleX = that.ScaleX;
     this.ScaleY = that.ScaleY;
     this.X = that.X;
     this.Y = that.Y;
 }
Ejemplo n.º 2
0
        public Key(Key that)
        {
            if (that.Bone != null)
            {
                Bone = new KeyBone
                {
                    Angle = that.Bone.Angle,
                    ScaleX = that.Bone.ScaleX,
                    ScaleY = that.Bone.ScaleY,
                    X = that.Bone.X,
                    Y = that.Bone.Y
                };
            }

            if (that.BoneRef != null)
            {
                BoneRef = new List<KeyBoneRef>();
                foreach (var keyBoneRef in that.BoneRef)
                {
                    BoneRef.Add(new KeyBoneRef
                    {
                        Id = keyBoneRef.Id,
                        Key = keyBoneRef.Key,
                        Parent = keyBoneRef.Parent,
                        Timeline = keyBoneRef.Timeline
                    });
                }
            }

            Id = that.Id;

            if (that.Object != null)
            {
                this.Object = new KeyObject
                {
                    Alpha = that.Object.Alpha,
                    Angle = that.Object.Angle,
                    File = that.Object.File,
                    Folder = that.Object.Folder,
                    PivotX = that.Object.PivotX,
                    PivotY = that.Object.PivotY,
                    ScaleX = that.Object.ScaleX,
                    ScaleY = that.Object.ScaleY,
                    X = that.Object.X,
                    Y = that.Object.Y
                };
            }

            if (that.ObjectRef != null)
            {
                ObjectRef = new List<KeyObjectRef>();
                foreach (var keyObjectRef in that.ObjectRef)
                {
                    ObjectRef.Add(new KeyObjectRef
                    {
                        Id = keyObjectRef.Id,
                        Key = keyObjectRef.Key,
                        Name = keyObjectRef.Name,
                        Parent = keyObjectRef.Parent,
                        Timeline = keyObjectRef.Timeline,
                        ZIndex = keyObjectRef.ZIndex
                    });
                }
            }

            Spin = that.Spin;
            Time = that.Time;
        }
Ejemplo n.º 3
0
        private static void CreateRuntimeObjectsForSpriterBoneRef(Key key, IDictionary<int, SpriterBone> persistentBones,
                                                                  SpriterObject SpriterObject,
                                                                  SpriterDataEntityAnimation animation, KeyFrame keyFrame,
                                                                  IDictionary<int, ScaledPositionedObject> boneRefDic, IDictionary<KeyFrameValues, int> boneRefParentDic, SpriterDataEntity entity,
                                                                  Key timelineKeyOverride = null)
        {
            IDictionary<int, KeyBone> bones = new Dictionary<int, KeyBone>();

            foreach (var boneRef in key.BoneRef)
            {
                SpriterBone bone;
                var timeline = animation.Timeline.Single(t => t.Id == boneRef.Timeline);

                if (persistentBones.ContainsKey(boneRef.Id))
                {
                    bone = persistentBones[boneRef.Id];
                }
                else
                {
                    var objectInfo = entity.ObjectInfos == null ? (ObjectInfo)null : entity.ObjectInfos.FirstOrDefault(o => o.Type == "bone" && o.Name == timeline.Name);
                    bone = new SpriterBone
                    {
                        Name = timeline.Name,
                        Length = objectInfo == null ? 200 : objectInfo.Width
                    };

                    bone.AttachTo(SpriterObject, true);

                    persistentBones[boneRef.Id] = bone;
                    SpriterObject.ObjectList.Add(bone);
                }

                var timelineKey = timelineKeyOverride ?? timeline.Key.Single(k => k.Id == boneRef.Key);
                if (timelineKeyOverride == null && key.Time != timelineKey.Time)
                {
                    var nextTimelineKey = timeline.Key.FirstOrDefault(k => k.Time > key.Time) ?? new Key(timeline.Key.First()) { Time = animation.Length };

                    timelineKey = InterpolateToNewTimelineKey(key, timelineKey, nextTimelineKey);
                }

                var timelineKeyBone = new KeyBone(timelineKey.Bone);

                bones[boneRef.Id] = timelineKeyBone;

                keyFrame.Values[bone] = new KeyFrameValues
                    {
                        RelativePosition = new Vector3(timelineKeyBone.X, timelineKeyBone.Y, 0.0f),
                        RelativeRotation = new Vector3(0.0f, 0.0f, timelineKeyBone.Angle),
                        RelativeScaleX = timelineKeyBone.ScaleX,
                        RelativeScaleY = timelineKeyBone.ScaleY,
                        Spin = timelineKey.Spin
                    };

                boneRefDic[boneRef.Id] = bone;
                if (boneRef.Parent.HasValue)
                {
                    boneRefParentDic[keyFrame.Values[bone]] = boneRef.Parent.Value;
                }
            }
        }