/// <summary> /// Initializes a new instance of the <see cref="Slot" /> class. /// </summary> /// <param name="data">The data.</param> /// <param name="skeleton">The skeleton.</param> /// <param name="bone">The bone.</param> /// <exception cref="System.ArgumentNullException">data cannot be null.</exception> public Slot(SlotData data, Skeleton skeleton, Bone bone) { if (data == null) { throw new ArgumentNullException("data cannot be null."); } if (skeleton == null) { throw new ArgumentNullException("skeleton cannot be null."); } if (bone == null) { throw new ArgumentNullException("bone cannot be null."); } this.Data = data; Skeleton = skeleton; Bone = bone; this.SetToBindPose(); }
/// <summary> /// Sets the value(s) for the specified time. /// </summary> /// <param name="skeleton">The skeleton.</param> /// <param name="time">The time.</param> /// <param name="alpha">The alpha.</param> public void Apply(Skeleton skeleton, float time, float alpha) { float[] frames = this.Frames; if (time < frames[0]) { // Time is before first frame. return; } int frameIndex; if (time >= frames[frames.Length - 1]) { // Time is after last frame. frameIndex = frames.Length - 1; } else { frameIndex = Animation.BinarySearch(frames, time, 1) - 1; } string attachmentName = this.AttachmentNames[frameIndex]; skeleton.Slots[this.SlotIndex].Attachment = attachmentName == null ? null : skeleton.GetAttachment(this.SlotIndex, attachmentName); }
/// <summary> /// Performs further custom initialization for this instance. /// </summary> /// <remarks> /// By default this method does nothing. /// </remarks> protected override void Initialize() { base.Initialize(); SkeletonJson json = new SkeletonJson(this.SkeletalData.Atlas); this.Skeleton = new Skeleton(json.ReadSkeletonData(this.animationPath)); if (string.IsNullOrEmpty(this.currentSkin)) { this.Skeleton.SetSkin(this.Skeleton.Data.DefaultSkin); } else { this.Skeleton.SetSkin(this.currentSkin); this.Skeleton.SetSlotsToBindPose(); } AnimationStateData stateData = new AnimationStateData(this.Skeleton.Data); this.state = new AnimationState(stateData); this.state.EndAnimation += this.OnEndAnimation; }
/// <summary> /// Attach all attachments from this skin if the corresponding attachment from the old skin is currently attached. /// </summary> /// <param name="skeleton">The skeleton.</param> /// <param name="oldSkin">The old skin.</param> internal void AttachAll(Skeleton skeleton, Skin oldSkin) { foreach (KeyValuePair<KeyValuePair<int, string>, Attachment> entry in oldSkin.attachments) { int slotIndex = entry.Key.Key; Slot slot = skeleton.Slots[slotIndex]; if (slot.Attachment == entry.Value) { Attachment attachment = this.GetAttachment(slotIndex, entry.Key.Value); if (attachment != null) { slot.Attachment = attachment; } } } }
/// <summary> /// Sets the animation. /// </summary> /// <param name="animation">The animation.</param> /// <param name="loop">if set to <c>true</c> [loop].</param> /// <param name="mixDuration">Mix duration</param> /// /// <param name="skeleton">Animation skeleton</param> public void SetAnimation(Animation animation, bool loop, float mixDuration, Skeleton skeleton) { if (this.Animation != null) { if (this.previous != null) { this.Animation.Mix(skeleton, this.Time, this.Loop, 1); this.Data.SetMix(this.previous, this.Animation, 0); } this.Data.SetMix(this.Animation, animation, mixDuration); } this.queue.Clear(); this.SetAnimationInternal(animation, loop); }
/// <summary> /// Sets the animation. /// </summary> /// <param name="animationName">Name of the animation.</param> /// <param name="loop">if set to <c>true</c> [loop].</param> /// <param name="mixDuration">Mix duration</param> /// <param name="skeleton">Animation skeleton</param> /// <exception cref="System.ArgumentException">Animation not found: + animationName</exception> public void SetAnimation(string animationName, bool loop, float mixDuration, Skeleton skeleton) { Animation animation = this.Data.SkeletonData.FindAnimation(animationName); if (animation == null) { throw new ArgumentException("Animation not found: " + animationName); } this.SetAnimation(animation, loop, mixDuration, skeleton); }
/// <summary> /// Applies the specified skeleton. /// </summary> /// <param name="skeleton">The skeleton.</param> public void Apply(Skeleton skeleton) { if (Animation == null) { return; } if (this.previous != null) { this.previous.Apply(skeleton, this.previousTime, this.previousLoop); float alpha = this.mixTime / this.mixDuration; if (alpha >= 1) { alpha = 1; this.previous = null; } Animation.Mix(skeleton, this.Time, this.Loop, alpha); } else { Animation.Apply(skeleton, this.Time, this.Loop); } }
/// <summary> /// Poses the skeleton at the specified time for this animation mixed with the current pose. /// </summary> /// <param name="skeleton">The skeleton.</param> /// <param name="time">The time.</param> /// <param name="loop">if set to <c>true</c> [loop].</param> /// <param name="alpha">The amount of this animation that affects the current pose.</param> /// <exception cref="System.ArgumentNullException">skeleton cannot be null.</exception> public void Mix(Skeleton skeleton, float time, bool loop, float alpha) { if (skeleton == null) { throw new ArgumentNullException("skeleton cannot be null."); } if (loop && this.Duration != 0) { time %= this.Duration; } List<ITimeline> timelines = this.Timelines; for (int i = 0, n = timelines.Count; i < n; i++) { timelines[i].Apply(skeleton, time, alpha); } }